on MBED,(with bread board)connect 11 12 13 14 to 5 6 7 8 Does this also work on app board?
Fork of SPI_HelloWorld_Mbed by
Revision 1:024296d963b5, committed 2013-11-09
- Comitter:
- avnisha
- Date:
- Sat Nov 09 04:45:41 2013 +0000
- Parent:
- 0:466ad3f38b6b
- Commit message:
- ok
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 466ad3f38b6b -r 024296d963b5 main.cpp --- a/main.cpp Tue Feb 12 17:25:49 2013 +0000 +++ b/main.cpp Sat Nov 09 04:45:41 2013 +0000 @@ -1,27 +1,45 @@ #include "mbed.h" -SPI spi(p5, p6, p7); // mosi, miso, sclk -DigitalOut cs(p8); +SPI spi(p11, p12, p13); // mosi, miso, sclk +DigitalOut cs(p14); +SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel + +char receive = 0; // returned by slave +char send = 0; // sent by master + +void slave_init() { + device.reply(receive++); + return; +} + int main() { + + int slave_byte; + + // init slave + + slave_init(); + // 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; + spi.frequency(1000000);; - // 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 + while (1) { + cs = 0; + slave_byte = spi.write(send++); + printf("slave byte = 0x%X\r\n", slave_byte); + cs = 1; + slave_init(); // give slave SPI time slice + wait(1); + } + +} + + \ No newline at end of file