on MBED,(with bread board)connect 11 12 13 14 to 5 6 7 8 Does this also work on app board?

Dependencies:   mbed

Fork of SPI_HelloWorld_Mbed by mbed official

Committer:
avnisha
Date:
Sat Nov 09 04:45:41 2013 +0000
Revision:
1:024296d963b5
Parent:
0:466ad3f38b6b
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:466ad3f38b6b 1 #include "mbed.h"
mbed_official 0:466ad3f38b6b 2
avnisha 1:024296d963b5 3 SPI spi(p11, p12, p13); // mosi, miso, sclk
avnisha 1:024296d963b5 4 DigitalOut cs(p14);
avnisha 1:024296d963b5 5 SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
avnisha 1:024296d963b5 6
avnisha 1:024296d963b5 7 char receive = 0; // returned by slave
avnisha 1:024296d963b5 8 char send = 0; // sent by master
avnisha 1:024296d963b5 9
avnisha 1:024296d963b5 10 void slave_init() {
avnisha 1:024296d963b5 11 device.reply(receive++);
avnisha 1:024296d963b5 12 return;
avnisha 1:024296d963b5 13 }
mbed_official 0:466ad3f38b6b 14
avnisha 1:024296d963b5 15
mbed_official 0:466ad3f38b6b 16 int main() {
avnisha 1:024296d963b5 17
avnisha 1:024296d963b5 18 int slave_byte;
avnisha 1:024296d963b5 19
avnisha 1:024296d963b5 20 // init slave
avnisha 1:024296d963b5 21
avnisha 1:024296d963b5 22 slave_init();
avnisha 1:024296d963b5 23
mbed_official 0:466ad3f38b6b 24 // Chip must be deselected
avnisha 1:024296d963b5 25
mbed_official 0:466ad3f38b6b 26 cs = 1;
mbed_official 0:466ad3f38b6b 27
mbed_official 0:466ad3f38b6b 28 // Setup the spi for 8 bit data, high steady state clock,
mbed_official 0:466ad3f38b6b 29 // second edge capture, with a 1MHz clock rate
avnisha 1:024296d963b5 30
mbed_official 0:466ad3f38b6b 31 spi.format(8,3);
avnisha 1:024296d963b5 32 spi.frequency(1000000);;
mbed_official 0:466ad3f38b6b 33
avnisha 1:024296d963b5 34 while (1) {
avnisha 1:024296d963b5 35 cs = 0;
avnisha 1:024296d963b5 36 slave_byte = spi.write(send++);
avnisha 1:024296d963b5 37 printf("slave byte = 0x%X\r\n", slave_byte);
avnisha 1:024296d963b5 38 cs = 1;
avnisha 1:024296d963b5 39 slave_init(); // give slave SPI time slice
avnisha 1:024296d963b5 40 wait(1);
avnisha 1:024296d963b5 41 }
avnisha 1:024296d963b5 42
avnisha 1:024296d963b5 43 }
avnisha 1:024296d963b5 44
avnisha 1:024296d963b5 45