SPI Hello World

Dependencies:   mbed

mbed 2 and mbed OS 5

This is an mbed 2 example. For an mbed-os example, please see:

Import programSPI_HelloWorld

SPI Hello World

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Feb 12 17:25:49 2013 +0000
Commit message:
SPI Hello World

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 466ad3f38b6b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 12 17:25:49 2013 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+ 
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut cs(p8);
+ 
+int main() {
+    // Chip must be deselected
+    cs = 1;
+
+    // Setup the spi for 8 bit data, high steady state clock,
+    // second edge capture, with a 1MHz clock rate
+    spi.format(8,3);
+    spi.frequency(1000000);
+ 
+    // Select the device by seting chip select low
+    cs = 0;
+ 
+    // Send 0x8f, the command to read the WHOAMI register
+    spi.write(0x8F);
+ 
+    // Send a dummy byte to receive the contents of the WHOAMI register
+    int whoami = spi.write(0x00);
+    printf("WHOAMI register = 0x%X\n", whoami);
+ 
+    // Deselect the device
+    cs = 1;
+}
\ No newline at end of file
diff -r 000000000000 -r 466ad3f38b6b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 12 17:25:49 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59
\ No newline at end of file