retrying spi on frdm (with interrupts)
Dependencies: mbed
Revision 0:7795ca374c24, committed 2015-04-07
- Comitter:
- armdran
- Date:
- Tue Apr 07 12:22:38 2015 +0000
- Commit message:
- retrying spi on frdm (with interrupts)
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 |
diff -r 000000000000 -r 7795ca374c24 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 07 12:22:38 2015 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" + +//SPI Slave +SPISlave device(D11, D12, D13, D10); // mosi, miso, sclk, ssel //nope +Serial pc(USBTX, USBRX); +DigitalOut ir(D9); + +uint8_t spi_reply_blocking(uint8_t reply = 0x00, bool sendIr = 0) { + device.reply(reply); + if(sendIr) { + ir = 1; + printf("ir sent\r\n"); + ir = 0; + } + + while(!device.receive()) {} + + return device.read(); +} + +int main() { + ir = 0; + pc.baud(9600); + printf("init\r\n"); + + device.format(8, 1); + device.frequency(1000000); + + + while(1) { + int pass = 0; + int fail = 0; + int miss = 0; + + for (uint8_t keystroke = 16; keystroke < 116; keystroke++) { + + if(spi_reply_blocking(0, 1) == 0xFE) { + spi_reply_blocking(keystroke); + + if(spi_reply_blocking() != keystroke) { + fail++; + } else { + pass++; + } + } else { + miss++; + } + + printf("fail: %d pass: %d missed: %d. press any key.\r\n", fail, pass, miss); + pc.getc(); + + } + + + + } + }
diff -r 000000000000 -r 7795ca374c24 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 07 12:22:38 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file