2015-05-18 12:43 AM
Hi everyone,
I'm working on custom board connecting STM32L152 to MX25L8006E (serial flash) using SPI driver. The SS is handle by me (software). I'm writing 24 bytes to some address and when i read from same address the first byte is always 0xFF. It is not issue with serial flash because on the scope i can see that MISO signal is currect. Waht can be the issue ???? below you can find my Read/Write functions ://Send
void SendDataSpiControl(BYTE a_data) { //< Wait until the transmit buffer is empty //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) { } //!< Send the byte //~~~~~~~~~~~~~~~~~~~~~~~~~ SPI_I2S_SendData(SPI1, a_data); //!< Wait to receive a byte //~~~~~~~~~~~~~~~~~~~~~~~~~ while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET){} //!< Return the byte read from the SPI bus //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //return SPI_I2S_ReceiveData(ETH_SPI); } //Receive uint8_t ReciveDataSpiControl(void) { uint8_t Data = 0; //!< Wait until the transmit buffer is empty //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET){} //!< Send the byte //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SPI_I2S_SendData(SPI1, SD_DUMMY_BYTE); //!< Wait until a data is received //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET){} //!< Get the received data //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ g_opSpiControl->m_receiveByte = SPI_I2S_ReceiveData(SPI1); // !< Return the shifted data //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ return g_opSpiControl->m_receiveByte; } Thanks in advance, Moran2015-05-18 06:14 AM
Consider the setting of RXNE, and if it reflects old stale data. ie try clearing it before sending.
2015-05-18 07:58 AM
Thanks Clive it work.
I've add to receive function one read before sending the dummy byte . my SPI read code ://Receive
uint8_t ReciveDataSpiControl(void) { uint8_t Data = 0; //!< Wait until the transmit buffer is empty //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET){}// this read is only to clean the garbage from data register
SPI_I2S_ReceiveData(SPI1); //!< Send the byte //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SPI_I2S_SendData(SPI1, SD_DUMMY_BYTE); //!< Wait until a data is received //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET){} //!< Get the received data //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ g_opSpiControl->m_receiveByte = SPI_I2S_ReceiveData(SPI1); // !< Return the shifted data //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ return g_opSpiControl->m_receiveByte; }