cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S003 - SPI Receive

bjerman
Associate II
Posted on August 30, 2015 at 01:49

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: 0690X000006051mQAA.png This is the capture from the logic analyzer: 0690X00000604qzQAA.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?
0 REPLIES 0