Other Parts Discussed in Thread: MSP430F5438
Hi,
I am interfacing Micron SPI NOR flash N25Q00AA to MSP430, Currently I am able to read Device ID successfully from SPI flash which is 0x20BA21, which shows the SPI configuration that i have done is corret. But I am not able to write/read from the SPI flash every time I am getting 0 as read result. Following are the code snippets.
void FlashTest(void)
{
uint8_t uReadByte=0;
for (int i=0; i<3; i++)
{
// printf("ID = %X\r\n",sFLASH_ReadID());
if(sFLASH_ReadID() == sFLASH_N25Q00_ID)
printf("N25Q00AA Flash Found\r\n");
else
printf("ERROR Flash not found\r\n");
}
__delay_cycles(10);
//printf("sFLASH_ReadReg() = %X\r\n",sFLASH_ReadReg(sFLASH_CMD_RDSR));
#if 1
//Test two bytes read/write
sFLASH_CS_LOW();
sFLASH_SendByte(sFLASH_CMD_WREN);
// __delay_cycles(10);
sFLASH_CS_HIGH();
sFLASH_CS_LOW();
sFLASH_SendByte(sFLASH_CMD_WRITE);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
sFLASH_SendByte(0xAA);
//__delay_cycles(10);
sFLASH_CS_HIGH();
sFLASH_CS_LOW();
sFLASH_SendByte(sFLASH_CMD_WRITE);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
sFLASH_SendByte(1);
sFLASH_SendByte('B');
//__delay_cycles(10);
sFLASH_CS_HIGH();
sFLASH_CS_LOW();
sFLASH_SendByte(sFLASH_CMD_READ);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
printf("First byte %X\r\n",sFLASH_SendByte(sFLASH_DUMMY_BYTE));
// uReadByte = sFLASH_SendByte(0);
//__delay_cycles(10);
sFLASH_CS_HIGH();
sFLASH_CS_LOW();
sFLASH_SendByte(sFLASH_CMD_READ);
sFLASH_SendByte(0);
sFLASH_SendByte(0);
sFLASH_SendByte(1);
printf("2nd byte %X\r\n",sFLASH_SendByte(sFLASH_DUMMY_BYTE));
// uReadByte = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
__delay_cycles(10);
sFLASH_CS_HIGH();
#endif
}
void ConfigureSPIFlash(void)
{
//Configure SPI GPIO
P3DIR |= FLASH_nCS; // Chip select for flash //0x40;
P3SEL |= FLASH_MOSI; // Peripheral module function is selected as UCB1SIMO MOSI on SPI
P5SEL |= FLASH_MISO | FLASH_SCK; //Select Port 5 Alternate function UCB1SOMI and UCB1CLK
//Configure SPI for Flash
//data present at serial data inputs are latched on the rising edge of the clock. Data is shifted out on the falling edge of the clock.
UCB1CTL1 |= UCSWRST; // Enabled. USCI logic held in reset state.
UCB1CTL0 = UCMST + UCMSB + UCSYNC + UCCKPH ; //3-Pin SPI with 8 bit SPI master, Clock Ideally Low, and MSB first,
//UCCKPH=1:Data is captured on the first UCLK edge and changed on the following edge.
//TODO Check Clock source once Crystal works
UCB1CTL1 |= UCSSEL_2; //Select SMCLK SubSystemCLOCK
UCB1BR0 = 0x00 ;
UCB1BR1 = 0;
// UCB1IE |= UCRXIE + UCTXIE; // Enable USCI_A0 RX interrupt
UCB1CTL1 &= ~UCSWRST; //Disable Reset
}
uint8_t sFLASH_SendByte(uint8_t uData)
{
UCB1TXBUF = uData; // write
while ((UCB1IFG & UCTXIFG)== 0);
while ((UCB1IFG & UCRXIFG) == 0); // wait for transfer to complete
return(UCB1RXBUF);
}
Can someone give me some pointers what I would be missing?
