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.
Fork of SPI_HelloWorld_Mbed by
main.cpp@0:466ad3f38b6b, 2013-02-12 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Feb 12 17:25:49 2013 +0000
- Revision:
- 0:466ad3f38b6b
- Child:
- 2:bae323a425ec
SPI Hello World
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 0:466ad3f38b6b | 1 | #include "mbed.h" |
| mbed_official | 0:466ad3f38b6b | 2 | |
| mbed_official | 0:466ad3f38b6b | 3 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
| mbed_official | 0:466ad3f38b6b | 4 | DigitalOut cs(p8); |
| mbed_official | 0:466ad3f38b6b | 5 | |
| mbed_official | 0:466ad3f38b6b | 6 | int main() { |
| mbed_official | 0:466ad3f38b6b | 7 | // Chip must be deselected |
| mbed_official | 0:466ad3f38b6b | 8 | cs = 1; |
| mbed_official | 0:466ad3f38b6b | 9 | |
| mbed_official | 0:466ad3f38b6b | 10 | // Setup the spi for 8 bit data, high steady state clock, |
| mbed_official | 0:466ad3f38b6b | 11 | // second edge capture, with a 1MHz clock rate |
| mbed_official | 0:466ad3f38b6b | 12 | spi.format(8,3); |
| mbed_official | 0:466ad3f38b6b | 13 | spi.frequency(1000000); |
| mbed_official | 0:466ad3f38b6b | 14 | |
| mbed_official | 0:466ad3f38b6b | 15 | // Select the device by seting chip select low |
| mbed_official | 0:466ad3f38b6b | 16 | cs = 0; |
| mbed_official | 0:466ad3f38b6b | 17 | |
| mbed_official | 0:466ad3f38b6b | 18 | // Send 0x8f, the command to read the WHOAMI register |
| mbed_official | 0:466ad3f38b6b | 19 | spi.write(0x8F); |
| mbed_official | 0:466ad3f38b6b | 20 | |
| mbed_official | 0:466ad3f38b6b | 21 | // Send a dummy byte to receive the contents of the WHOAMI register |
| mbed_official | 0:466ad3f38b6b | 22 | int whoami = spi.write(0x00); |
| mbed_official | 0:466ad3f38b6b | 23 | printf("WHOAMI register = 0x%X\n", whoami); |
| mbed_official | 0:466ad3f38b6b | 24 | |
| mbed_official | 0:466ad3f38b6b | 25 | // Deselect the device |
| mbed_official | 0:466ad3f38b6b | 26 | cs = 1; |
| mbed_official | 0:466ad3f38b6b | 27 | } |
