TEAMUSB / Mbed 2 deprecated SPI_Master_arch

Dependencies:   USBDevice mbed

Fork of SPI_HelloWorld_Mbed by mbed official

Committer:
wlangenkamp
Date:
Wed Mar 11 15:59:56 2015 +0000
Revision:
3:849c7a28b185
Parent:
2:bae323a425ec
Child:
4:fb6fa24b502c
Hoi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:466ad3f38b6b 1 #include "mbed.h"
armdran 2:bae323a425ec 2 #include "USBSerial.h"
wlangenkamp 3:849c7a28b185 3
armdran 2:bae323a425ec 4 SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk
armdran 2:bae323a425ec 5 USBSerial serial;
wlangenkamp 3:849c7a28b185 6 Serial pc(USBTX, USBRX);
armdran 2:bae323a425ec 7 DigitalOut led(LED1);
wlangenkamp 3:849c7a28b185 8 DigitalOut cs(P0_2);
mbed_official 0:466ad3f38b6b 9
mbed_official 0:466ad3f38b6b 10 int main() {
mbed_official 0:466ad3f38b6b 11
armdran 2:bae323a425ec 12 spi.format(8,0);
wlangenkamp 3:849c7a28b185 13 spi.frequency(1000000);
armdran 2:bae323a425ec 14 uint8_t i = 0;
armdran 2:bae323a425ec 15
armdran 2:bae323a425ec 16 while(1) {
wlangenkamp 3:849c7a28b185 17 cs = 0;
armdran 2:bae323a425ec 18 // Setup the spi for 8 bit data, high steady state clock,
armdran 2:bae323a425ec 19 // second edge capture, with a 1MHz clock rate
armdran 2:bae323a425ec 20
armdran 2:bae323a425ec 21 // Send 0x8f, the command to read the WHOAMI register
armdran 2:bae323a425ec 22 //spi.write(0x8f);
armdran 2:bae323a425ec 23 //spi.write(i);
armdran 2:bae323a425ec 24
armdran 2:bae323a425ec 25 // Send a dummy byte to receive the contents of the WHOAMI register
armdran 2:bae323a425ec 26 //int whoami = spi.write(0x00);
armdran 2:bae323a425ec 27 //serial.printf("WHOAMI register = 0x%X\r\n", whoami);
wlangenkamp 3:849c7a28b185 28 wait(1.5);
armdran 2:bae323a425ec 29 uint8_t receive = spi.write(i);
armdran 2:bae323a425ec 30 serial.printf("send: 0x%X; received: = 0x%X\r\n", i, receive);
wlangenkamp 3:849c7a28b185 31 cs = 1;
wlangenkamp 3:849c7a28b185 32 wait(0.5);
armdran 2:bae323a425ec 33 led = 1;
wlangenkamp 3:849c7a28b185 34 wait(1);
armdran 2:bae323a425ec 35 led = 0;
armdran 2:bae323a425ec 36 i++;
armdran 2:bae323a425ec 37 }
armdran 2:bae323a425ec 38
mbed_official 0:466ad3f38b6b 39 }