cancel
Showing results for 
Search instead for 
Did you mean: 

�asking for help】SPI slave sending wrong data to the master!!!!

970253146
Associate II
Posted on June 09, 2015 at 11:42

Last time I posted here to see if somebody can help me to solve my problem.I used two stm32 chips to exchange one byte data using SPI.But the data receiving from the slave was two bit or one bit wrong,such as 11110000 would become 00111100.I checked my program,the polarity and edge configuration are correct.Can someone tell me what happen inside out? Is it a matter of Stm32 hardward or Is it my fault????I have been taken down by this problem for a week.

2 REPLIES 2
AvaTar
Lead
Posted on June 09, 2015 at 12:39

Is it a matter of Stm32 hardward or Is it my fault????

 

Not much detail to start with, but since you are not the only one to try SPI, it is almost certainly you, and not the hardware. (When my applications don't work, I always start with this presumption).

I checked my program,the polarity and edge configuration are correct.

 

Do you have a scope to verify such statements ?

As a start, I would have the slave always send the same data byte,  so you can easily check transmission and reception.

But the data receiving from the slave was two bit or one bit wrong,such as 11110000 would become 00111100.

 

This sounds like your slave sees more clock pulses than he should. How do you handle slave select (NSS) ? Perhaps the slave is already 'listening' while the master is still being initialised ?

Posted on June 10, 2015 at 05:39

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Hello%20everyone%2ccould%20u%20please%20help%20me%20with%20a%20problem%20I%20got%20in%20learning%20the%20SPI%20of%20Stm32%2cthank%20you%20very%20much&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=45]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fHello%20everyone%2ccould%20u%20please%20help%20me%20with%20a%20problem%20I%20got%20in%20learning%20the%20SPI%20of%20Stm32%2cthank%20you%20very%20much&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FAllItems.aspx¤tviews=45

Your problem seems to be one of expecting two processors running asynchronously from each other to some how magically be in sync when you chose to transact data.

The master needs to wait for the slave to be ready, and you need to use GPIO pins to confirm that. The master would normally use a Chip Select, but that is no guarantee the slave is up running, and ready yet.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..