Why is there corrupt data when sending as SPI Slave?
- November 29, 2021
- 6 replies
- 10302 views
Hello!
I have been trying to configure the STM32F407VE as a SPI slave. My first time configuring a SPI device ever so its all new to me. You can see my SPI settings and code as an attachment.
I am using software SS as I only have one slave and one master. Though I am polling the SS line of the master device to make sure I sync up okay as I best as I can before I only react on the master's clock signals later.
The master device is a playstation 2 running a playstation 1 game. So far what I observe on my logic analyzer matches online docs which is reassuring. Here are the docs I am referring to.
https://gamesx.com/controldata/psxcont/psxcont.htm
https://store.curiousinventor.com/guides/PS2
Where I am so far is that I am able to receive a byte from the master and am able to take some action on it. For my example, I can issue an acknowledge to the master to say I got the data okay. From what I understand, this is not part of SPI but is required when talking to a playstation 2 or 1 before it sends another byte. I have confirmed that to be true when I sent the acknowledge after the first byte exchange.
Now whenever I grabbed a byte from the master, I send a dummy byte of 0xFF to the master (full duplex). When i try to send any other value as the dummy byte, the MCU sends completely random values. There is no rhyme or reason I could find in the few hours of debugging.
I believe it has to be something wrong on how I send the byte but I think the order of actions I have makes sense as far as I concluded from reading the reference manual. Then again I am new to SPI congfiuratoin so I think there still might be an error
Has anyone else have had this strange behavior when trying to use the STM32 as a SPI slave? There are not too many examples on the internet I could find on how to do this. Those that try seem to never get it working quite right and seem to abandon the idea. There was one website I found that used one STM32 master and STM32 slave. It looked easy enough to do with the HAL but I came across similar issues so it didn't work for me.
Any hints or troubleshooting starting points is appreciated. Thank you for your time in reading my post!
Other Notes:
1) I am using the STM32CubeIDE.
2) I am using HAL for configuration.
3) Last task I had was using UARTs (and lots of I/O) and everything worked okay so I think my hardware is okay.
4) It is a custom PCB I made for my own STM32 development and learning.
5) To see data line routing on my PCB, it is attached but I think it looks okay.
6) Clock tree is attached.