cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding the SPI Peripheral when accepting and sending data.

JCorl.1
Senior

I have my STM32F407VE successfully configured as a slave device. Goal is to emulate a PlayStation 2 controller.

Where I am at right now is that I am trying to send a specific order of bytes so I can be sure that before I read and act on the command byte, I am able to properly send the required 5 byte payload. Basically, the console sends 5 bytes with a certain game I use when a controller is connected: 0x01, 0x42, 0x00, 0x00, 0x00. For this game, it never changes since it doesn't need other commands like for analog joystick read and such.

So all I do is receive a byte and then pulse the acknowledge line (required so the consoles knows I read it). For each exchange, I send the proper bytes that a real controller would which are: 0xFF, 0x41, 0x5A, 0xFF, 0xFF. Sounds easy enough.

When I send with one byte to begin, everything looks good. When I send with two bytes, still looks good. But when I try a 3rd byte, it seems as though the interrupt I have that is triggered from the chip select line is not sync'd correctly. The byte order also becomes messed up because of this. There must be something fundamentally wrong on how I understand the SPI module behaves but I can't quite understand why yet.

I have my interrupt code snippet and the byte screenshots attached.

10 REPLIES 10
JCorl.1
Senior

Ok yeah that was def the way to do it! The game finally went to another menu when I decided to spam the START bit. Thanks again for the suggestions!

0693W00000GZgWIQA1.png