STM32F407 - Flag RXNE of SPI is clear when i read. Sometimes is stack in waiting the flag.

Hi, i using SPI for communicating Transmiting and Receiving with STM32F407. My routine for transmit:

void spi_transmit(uint8_t DataX)
while(!(SPI_TFT->SR & SPI_SR_TXE));
SPI_TFT->DR = DataX;

while(!(SPI_TFT->SR & SPI_SR_RXNE));

while(SPI_TFT->SR & SPI_SR_BSY);


My problem is that in normal function, arbitrary the program counter is stack in the waiting of flag SPI_SR_RXNE=1. If i debug step by step, when i read SPI_SR_RXNE, it clears and never continue. Why is that? i cant understand.

More questions in this forum