Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Master.cpp
- Revision:
- 13:8f54a702b9aa
- Parent:
- 12:99c0f833a7de
- Child:
- 15:4edd16cdc84b
--- a/Master.cpp Tue Nov 12 20:28:46 2013 +0000
+++ b/Master.cpp Tue Nov 12 21:24:53 2013 +0000
@@ -1,6 +1,32 @@
#include "mbed.h"
#include "SPI.h"
-SPI device(p1, p2, p3); //mosi, miso, sclk;
-
-
+SPI device(p5, p6, p7); //mosi, miso, sclk
+DigitalOut cs1(p8); //cs1 = chip select - slave 1
+DigitalOut cs2(p9); //cs2 = chip select - slave 2
+DigitalOut cs3(p10); //cs3 = chip select - slave 3
+
+int main() {
+ // Chip must be deselected
+ cs1 = 1;
+ cs2 = 1;
+ cs3 = 1;
+
+ // Setup the spi for 8 bit data, high steady state clock,
+ // second edge capture, with a 1MHz clock rate
+ device.format(8,3);
+ device.frequency(1000000);
+
+ // Select the device by seting chip select low
+ cs1 = 0;
+
+ // Send 0x8f, the command to read the WHOAMI register
+ device.write(0x8F);
+
+ // Send a dummy byte to receive the contents of the WHOAMI register
+ int whoami = device.write(0x00);
+ printf("WHOAMI register = 0x%X\n", whoami);
+
+ // Deselect the device
+ cs1 = 1;
+}
\ No newline at end of file
