This example demonstrates the reading of the PlayStation controller in the Nucleo.

Dependencies:   mbed

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

/media/uploads/beaglescout007/nucleo_ex03_pspad.png This circuit diagram was created by fritzing.

PS con.Nucleo
1MISO PC_11 PullUp
2MOSI PC_12
3-
4GND
53.3v 3v3
6CS PD_2
7SCK PC_10
8-
9-

/media/uploads/beaglescout007/pad_conector.jpg

https://youtu.be/Ff4FVxsXCE0

Files at this revision

API Documentation at this revision

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