2025-01-25 10:45 PM
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
2025-01-26 05:39 AM
Hi,
did you check: same/or matching setting for the spi clock ?
see, in Cube:
Has to match, what you send from ESP8266 . Otherwise you receive...nonsense.
2025-01-26 06:09 AM
Are you using a CS line to sync master/slave? Can you show the traces of CS/SCK/MOSI/MISO?
2025-02-03 01:09 AM
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
2025-02-03 05:35 AM - edited 2025-02-03 05:54 AM
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.