This example demonstrates the reading of the PlayStation controller in the Nucleo.
Intro
This example demonstrates the reading of the PlayStation controller in the Nucleo.
Parts
STM32 Nucleo F446RE |
Connector for the PS controller |
LED 2pcs |
Register 100k ohm |
Register 470 ohm 2pcs |
Breadboard |
Wires |
Wiring diagram
This circuit diagram was created by fritzing.
PS con. | Nucleo |
---|---|
1 | MISO PC_11 PullUp |
2 | MOSI PC_12 |
3 | - |
4 | GND |
5 | 3.3v 3v3 |
6 | CS PD_2 |
7 | SCK PC_10 |
8 | - |
9 | - |
Revision 0:871415d77569, committed 2016-03-12
- Comitter:
- beaglescout007
- Date:
- Sat Mar 12 10:09:49 2016 +0000
- Commit message:
- Release
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 871415d77569 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Mar 12 10:09:49 2016 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" + +// SPI interface +SPI pad_spi(PC_12, PC_11, PC_10); // MOSI(should pullup), MISO, SCK +DigitalOut pad_cs(PD_2); + +// LED +DigitalOut red(PB_5); +DigitalOut yellow(PA_10); + +// PS pad initialize +void pspad_init() +{ + pad_spi.format(8, 3); + pad_spi.frequency(250000); +} + +// Read PS Pad state +// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +// SE -- -- ST U R D L L2 R2 L1 R1 TR O X SQ +void pspad_read(unsigned short *pad) +{ + pad_cs = 0; + wait_us(500); + + pad_spi.write(0x80); + pad_spi.write(0x42); + pad_spi.write(0); + pad_spi.write(0); + int d1 = pad_spi.write(0); + int d2 = pad_spi.write(0); + + pad_cs = 1; + + *pad = (char)~d1 << 8 | (char)~d2; +} + +int main() +{ + pspad_init(); + + unsigned short pad; + + while(1) + { + pspad_read(&pad); + + // Circle button + yellow = pad & 4; + + // X button + red = pad & 2; + + wait_ms(16); + } +} \ No newline at end of file
diff -r 000000000000 -r 871415d77569 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Mar 12 10:09:49 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file