cancel
Showing results for 
Search instead for 
Did you mean: 

Reading worng first byte from serial flash

moran
Associate II
Posted on May 18, 2015 at 09:43

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,

Moran
2 REPLIES 2
Posted on May 18, 2015 at 15:14

Consider the setting of RXNE, and if it reflects old stale data. ie try clearing it before sending.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
moran
Associate II
Posted on May 18, 2015 at 16:58

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;

}