SPI slave 11-03-15
Dependencies: mbed_SPISlave_LPC
Diff: main.cpp
- Revision:
- 0:e1961b6f09d3
diff -r 000000000000 -r e1961b6f09d3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 10 16:52:28 2015 +0000 @@ -0,0 +1,27 @@ + +// Reply to a SPI master as slave + +#include "mbed.h" + +Serial pc(USBTX, USBRX); // tx, rx + +SPISlave device(dp2, dp1, dp6, dp25); // mosi, miso, sclk, ssel + +int main() { + +// device.reply(0x00); // Prime SPI with first reply + while(1) { + + //pc.printf("hi\r\n"); + //wait(1); + + if(device.receive()) { + int v = device.read(); // Read byte from master + pc.printf("received: %x/r/n", v); // print v to serial + v = (v + 1) % 0x100; // Add one to it, modulo 256 + device.reply(v); // Make this the next reply + } + + wait(0.1); + } +} \ No newline at end of file