![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple SPI Slave test Application, intended to be used with SSM to show problems with the SPISlave.receive() method
Revision 0:8a63b2e87af8, committed 2011-08-26
- Comitter:
- picnic
- Date:
- Fri Aug 26 10:11:08 2011 +0000
- Commit message:
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 8a63b2e87af8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 26 10:11:08 2011 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" + +// Simple Spi Slave +// Simple SPI Slave receives bytes on the SPI and will echo back the byte received on the next request. + +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); +SPISlave spi(p11, p12, p13, p14); // mosi, miso, sclk, ssel + +int main() { + int v = 0xff; + long c = 0; + int ch; + int echoMode = 1; + + pc.printf("Simple SPI Slave Test\r\n"); + pc.printf("Uses MBED's SPISlave library (1 byte in - 1 byte out)\r\n"); + pc.printf("\r\n R : to add an extra reply() call\r\n" ); + pc.printf(" I : Make a read() call\r\n" ); + pc.printf(" S : Read receive status\r\n" ); + pc.printf(" N : No reply()\r\n" ); + spi.format(8,3); + + spi.reply( v ); + + while(1) { + if( spi.receive() ) { + // Data available - our trigger to do something + v = spi.read(); // Read byte from master + if ( echoMode ) { + // and send last data back + spi.reply( v ); + } + pc.printf( "%ld In %02x\r\n", c++, v ); + } + + if ( pc.readable() ) { + ch = pc.getc(); + switch ( ch ) { + case 'R': + case 'r': + spi.reply( 'B' ); + pc.printf( "Bogus Replay added\r\n" ); + break; + case 'I': + case 'i': + v = spi.read(); + pc.printf( "Extra read = %02x\r\n", v ); + break; + case 'S': + case 's': + v = spi.receive(); + pc.printf( "Status = %02x\r\n", v ); + break; + case 'N': + case 'n': + echoMode = !echoMode; + pc.printf( "Echo mode = %d\r\n", (echoMode & 1) ); + break; + } + } + } +}
diff -r 000000000000 -r 8a63b2e87af8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Aug 26 10:11:08 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912