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
Revision 4:fb6fa24b502c, committed 2015-03-16
- Comitter:
- armdran
- Date:
- Mon Mar 16 14:33:35 2015 +0000
- Parent:
- 3:849c7a28b185
- Commit message:
- 1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 849c7a28b185 -r fb6fa24b502c main.cpp --- a/main.cpp Wed Mar 11 15:59:56 2015 +0000 +++ b/main.cpp Mon Mar 16 14:33:35 2015 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "USBSerial.h" +//SPI Master + SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk USBSerial serial; Serial pc(USBTX, USBRX); @@ -14,25 +16,25 @@ uint8_t i = 0; while(1) { - cs = 0; - // Setup the spi for 8 bit data, high steady state clock, - // second edge capture, with a 1MHz clock rate - // Send 0x8f, the command to read the WHOAMI register - //spi.write(0x8f); - //spi.write(i); - - // Send a dummy byte to receive the contents of the WHOAMI register - //int whoami = spi.write(0x00); - //serial.printf("WHOAMI register = 0x%X\r\n", whoami); - wait(1.5); - uint8_t receive = spi.write(i); - serial.printf("send: 0x%X; received: = 0x%X\r\n", i, receive); + cs = 0; + wait_ms(1); + uint8_t dummy_response = spi.write(i); + wait_ms(1); cs = 1; - wait(0.5); - led = 1; - wait(1); - led = 0; + wait_ms(1); + cs = 0; + uint8_t response = spi.write(0xFF); + wait_ms(1); + cs = 1; + wait_ms(1); + + serial.printf("instruction: 0x%X; response: = 0x%X; dummy_response = 0x%X\r\n", i, response, dummy_response); + + wait(2); + led = 1; + wait(.5); + led = 0; i++; }