SPI Hello World
Fork of SPI_HelloWorld_Mbed by
Note
You will need to redefine the SPI pins to match the pins on your board to run this example. The pin mapping can be found on the board's Platform page.
API
API reference
Import librarymbed
main.cpp
- Committer:
- mbed_official
- Date:
- 2013-02-12
- Revision:
- 0:466ad3f38b6b
- Child:
- 2:34bd7b8d30f9
File content as of revision 0:466ad3f38b6b:
#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; }