cancel
Showing results for 
Search instead for 
Did you mean: 

Observing a data shift in SPI receiption

AADESH
Associate II

Hi Team,

I am observing a shift in a data each time i am sending same data from ESP8266 master to STM32f103RCT6 slave controller but each time i am getting different data and seems to be the shifted data as i can see some part of strings sent. 
I have observed with the logic analyzer and it is showing same data each time. 

I have attached the project and logic analyzer traces and data printed over putty from stm32 MCU, Please check the SPI configuration if i am doing anything wrong. 

Please help debug this issue. 

Thank you in advance!

 

Best Regards,

Aadesh

4 REPLIES 4
AScha.3
Chief III

Hi,

did you check: same/or matching setting for the spi clock ?

see, in Cube:

AScha3_0-1737898673180.png

Has to match, what you send from ESP8266 . Otherwise you receive...nonsense.

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

Are you using a CS line to sync master/slave? Can you show the traces of CS/SCK/MOSI/MISO?

If you feel a post has answered your question, please click "Accept as Solution".
AADESH
Associate II

Hi,

The SPI settings are correct and the data observed on the scope also correct.

however, at STM mcu side data received is wrong.

Currently i have removed the bitfields from the structure being sent over SPI. Now Data transfer is working fine.

Not sure what issues bit fields in the structure causing SPI data not read properly.

Best Regards,

Aadesh

Logic SPI config:
CPOL=0 polarity=0
CPHA=0 data is valid on leading edge
Logic diagram: data changes state half a period before first rising edge, sampled at each rising edge and update on each falling edge
so Logic SPI config is correct.


STM32CubeMX config:
CPOL=0
CPHA=1 <- this is incorrect

as the data is sampled exactly when it changes you may sample the old data or the new data. This explains shift in data and inconsistent results.
Configure CPHA=0 and it should work.

Edit:
I was wrong. In STM32CubeMX "CPHA=1 edge" means CPHA=0.

CPU clock and peripheral clock seem sufficient at 64MHz/32MHz for a 1MHz SPI signal.
Have you checked the voltage of the signal? Perhaps voltage level or rise time of the signal is not sufficient. The Logic analyzer might see the right signal, but the MCU might not or vice versa.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.