It is because on STM32F0, the flag SPI_I2S_FLAG_RXNE is set by default only when 16 bits (so 2 bytes) are received on MISO pin.
If you send 2 bytes and then do you while loop, you should exit of the loop very quickly.
The Reference Manual said (Section SPI status flags) :
The RXNE flag is set depending on the FRXTH bit value in the SPIx_CR2 register:
If FRXTH is set, RXNE goes high and stays high until the RXFIFO level is greater or equal to 1/4 (8-bit).
If FRXTH is cleared, RXNE goes high and stays high until the RXFIFO level is greater than or equal to 1/2 (16-bit).
So, if you want the flag SPI_I2S_FLAG_RXNE to be set when only 1 byte is received, you should use the following function :
SPI_RxFIFOThresholdConfig (SPIx, SPI_RxFIFOThreshold_QF);
- SPI_RxFIFOThreshold_QF: RXNE event is generated if the FIFO level is greater or equal to 1/4.
- SPI_RxFIFOThreshold_HF: RXNE event is generated if the FIFO level is greater or equal to 1/2. (default value)