V1.0 of SPI Slave Example for Serial Communications Workshop
Dependencies: mbed
Revision 0:45714e4b114f, committed 2015-03-06
- Comitter:
- MoffMade
- Date:
- Fri Mar 06 22:01:40 2015 +0000
- Commit message:
- V1.0 of SPI Slave Example for Serial Communications Workshop
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 06 22:01:40 2015 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +SPISlave spi(PTD2, PTD3, PTD1, PTD10); // mosi, miso, sclk, cs +Serial pc(USBTX, USBRX); // Configure UART +PwmOut g_led(LED_GREEN); // Configure Green LED + +int main() { + // 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); + // Configure PC/Serial Connection + pc.baud(9600); + + while(1) + { + char receivedValue = 0; + if(spi.receive()) { //Poll SPI module to see if a byte has been received + receivedValue = spi.read(); // Read Received value + if(receivedValue != 0x00) { + spi.reply(receivedValue); // Set reply when next byte is received + pc.printf("Received Data = 0x%X\n\r",receivedValue); // Output to PC Serial + g_led = 1.0f * receivedValue; // Set Green LED to be percentage value + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 06 22:01:40 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file