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:

Capture1.PNG

This is the capture from the logic analyzer:
Capture3.PNG

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)){}
    SPI_SendData(0x00);
    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?

Outcomes