AnsweredAssumed Answered

STM8S003 - SPI Receive

Question asked by Salieri on Aug 30, 2015
I'm at my wit's end, I cant seem to make SPI receive work properly.
This is a cut from the S003 reference manual:


This is the capture from the logic analyzer:

And this is the code where I'm trying to read the bloody SPI:

uint8_t SPI_TransferData(uint8_t Data)
    SPI_SendData(Data);; /* Write in the DR register the data to be sent*/
    while(((SPI->SR & (uint8_t)SPI_FLAG_TXE) != (uint8_t)RESET)){}
    while(((SPI->SR & (uint8_t)SPI_FLAG_RXNE) != (uint8_t)RESET)){}
    return ((uint8_t)SPI->DR);

Where data is 0x05 and I'm trying to get 0x02 as the return value.

I'm loosing my mind, and the STVD is definitely not helping with my sanity. I'd be extremely grateful for any help.

The code never returns from this line:
while(((SPI->SR & (uint8_t)SPI_FLAG_RXNE) != (uint8_t)RESET)){}

Why not? Even if my data is supposed to be shifted by one, I'm still supposed to be getting a valid 0x00, or am I wrong?