Simple SPI test Application, intended to be used with SSS to send data between 2 mbed devices

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
picnic
Date:
Fri Aug 26 10:10:11 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 26 10:10:11 2011 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+
+// Simple SPI Master
+// Simply sends incrementing bytes and receives the echo from the previous one
+
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut cs(p8);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+#define SINGLE 0
+#define CONTINUOUS 1
+
+    long c = 0;
+    unsigned char r = 0;
+    unsigned char v = 0;
+    int ch;
+
+void sendbyte() {
+    // Select the device by seting chip select low
+    cs = 0;
+    v = c & 0xff;
+    r = spi.write( v );
+    // Deselect the device
+    cs = 1;
+
+    pc.printf("%ld v=%02x\r\n", c, v);
+    if (( c>0 ) && ( r!=(unsigned char)(v-1)) ) {
+        pc.printf( "   Echo error %02x!=%02x\r\n", v-1, r );
+        pc.printf("Press any key to continue\r\n");
+        ch = pc.getc();
+    }
+    c++;
+}
+
+int main() {
+    int  mode = 0;
+    
+    pc.printf("Simple SPI Master Test\r\n");
+    pc.printf("Uses MBED's SPI library (1 byte in - 1 byte out)\r\n");
+    pc.printf("\r\n C : Toggle continuous mode\r\n" );
+    pc.printf(" T : Make a single transmission\r\n" );
+    
+    // Setup the spi
+    // second edge capture, with a 1MHz clock rate
+    spi.format(8,3);
+    spi.frequency(100000);
+
+    while (1) {
+        if ( mode ) {
+            wait_ms( 1 );
+            sendbyte();
+        }
+        if ( pc.readable() ) {
+            ch = pc.getc();
+            switch ( ch ) {
+                case 'C':
+                case 'c':
+                    mode = ! mode;
+                    break;
+                case 'T':
+                case 't':
+                    sendbyte();
+                    break;
+            }
+        }        
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 26 10:10:11 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912