Sog Yang
/
mbed_SPIS_multiByte_example_SOG
Sog update version
Fork of mbed_SPIS_multiByte_example by
Diff: main.cpp
- Revision:
- 0:b7415ae44dac
- Child:
- 1:58f0712d9aa2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 24 10:17:56 2017 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +#include "SPISlave_multiByte.h" +SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel +Serial uart(USBTX, USBRX); + +int main() { + uart.printf("START!"); + device.format(8,1); + + device.reply(0xAA); // Prime SPI with first reply + while(1) { + if(device.receive()) { + int v = device.read(); // Read byte from master + v = (v + 1) % 0x100; // Add one to it, modulo 256 + device.reply(v); // Make this the next reply + + v = device.read(); // Read byte from master + v = (v + 1) % 0x100; // Add one to it, modulo 256 + device.reply(v); // Make this the next reply + + v = device.read(); // Read byte from master + v = (v + 1) % 0x100; // Add one to it, modulo 256 + device.reply(v); // Make this the next reply + } + } +} \ No newline at end of file