用5438a读flash at45db161d,结果好像出现了移位。纠结中。xt2是12MHz
以下是代码:
void SpiInit(void)
{
//set UCSWRST
UCB2CTL1 |= UCSWRST; // **Put state machine in reset**
//Initialize USCI reg
UCB2CTL0 |= UCCKPL+UCCKPH; //SPI MODE 3
UCB2CTL0 |= UCMST+UCSYNC+UCMSB; //SPI master, MSB
UCB2CTL0 &= ~UC7BIT; // 8-bit
UCB2CTL0 &= ~UCMODE_0; //3-pin,
UCB2CTL1 |= UCSSEL_2; // SMCLK
UCB2BR0 = 6; // 2
UCB2BR1 = 0; //
// UCB2MCTL = 0; // No modulation
//Config ports
P9SEL |= BIT1+BIT2+BIT3; //P9.1 P9.2 P9.3功能选择为SPI
P9DIR |= BIT1; // SIMO output
P9DIR &= ~BIT2; // SOMI input
P9DIR |= BIT3; // CLK output
P9SEL &= ~BIT0; //P9.0 端口模式 SPI_FPGA
P9DIR |= BIT0; //P9.0输出,控制FPGA片选信号
P9OUT |= BIT0; //FPGA CS is high
P6SEL &= ~BIT4; //P6.4 端口模式 SPI_FLASH
P6SEL &= ~BIT6; //P6.6 端口模式 SPI_DAC
P6DIR |= BIT4 + BIT6; //p6.4/6输出,控制FLASH和DAC
P6OUT |= BIT4+BIT6; // FLASH and DAC are high
//Clear UCSWRST
UCB2CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
// UCB2IE |= UCRXIE; // Enable USCI_A0 RX interrupt
}
uint8 SpiRW(uint8 txdata)
{
uint8 rxdata;
uint8 retry = 0;
while(!(UCB2IFG & UCTXIFG)) // wait until last SPI-Transmission is finished
{
retry++;
if(retry > 200) return 0;
}
UCB2TXBUF = txdata; // send 8 clocks "txdata" and SPI-clocks
retry = 0;
while(!(UCB2IFG & UCRXIFG)) // wait until one byte is received
{
retry++;
if(retry > 200) return 0;
}
rxdata = UCB2RXBUF;
return rxdata;
}
#define At45dbEnable() P6OUT &= ~BIT4 /*; delay_us(1)*/
#define At45dbDisable() /*delay_us(1);*/P6OUT |= BIT4
uint8 At45dbStatus(void)
{
uint8 status;
At45dbEnable();
SpiRW(STATUS_REGISTER);
status = SpiRW(0x00);
At45dbDisable();
return status;
}
void main(void)
{
uint8 status;
WDT_Init();
SetVcoreUp(PMMCOREV_1);// Set VCore to 1.8MHz for 12MHz
sysClock_Init();
SpiInit();
delay_ms(300);
status = At45dbStatus();
while(1);
}
正确的应该是:status =0bxx1011xx,
而返回的结果值: status = 0b01010110 (HEX: 0x56);好像是作了移位。
mcu配置的SPI是模式3,可波形却是如下图: