STM32F301 SPI read FIFO flush does not seem to work
STM32F301R8T6(Master)
M95160-WMN6TP EEPROM(Slave)
Low Level drivers
I've been trying to do a basic SPI EEPROM test based on the STM32F30x_DSP_StdPeriph_Lib_V1.2.3 SPI EEPROM example. Have finally gotten the write to work correctly but when we begin the read back from the EEPROM we see an extra three bytes of zeros in the receive buffer. The SPI bus analyzer shows the correct data coming out of the EEPROM chip so it seems that the RX FIFO still has data in it from the three read command bytes sent to the EEPROM(0x03, 0x00, 0x20, read command and address.) I've tried code examples from this site for flushing the RX FIFO but when running at full speed(i.e. not stopping in the debugger) there still is an extra three 0x00 getting into the receive buffer.
When stepping in the debugger as we enter the flush function the SPI3->SR register shows a receive buffer not empty(RXNE) and a FIFO reception level(FRLVL) of 0x3(FIFO full.) After a single read of the SPI3->DR register the RXNE clears and FRLVL changes to 0x0. If the FIFO receive buffer is full a single read should still leave 3 bytes in the FIFO not suddenly go to empty. I think we are missing something very basic here or are seeing some weird debugger induced issue. Any suggestions?
Thanks
TestStatus SPI_FlushRxFifo(SPI_TypeDef *hspi)
{
__IO uint32_t tmpreg;
uint8_t count = 0U;
while (SPI_GetReceptionFIFOStatus(SPI3) != SPI_ReceptionFIFOStatus_Empty)
//while (hspi->SR & SPI_I2S_FLAG_RXNE)
{
count++;
tmpreg = hspi->DR;
/* To avoid GCC warning */
(void)tmpreg;
if (count == 4)
{
return FAILED;
}
}
return PASSED;
}