SPI slave 11-03-15

Dependencies:   mbed_SPISlave_LPC

Files at this revision

API Documentation at this revision

Comitter:
Matt3
Date:
Tue Mar 10 16:52:28 2015 +0000
Commit message:
a

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.lib 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	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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Tue Mar 10 16:52:28 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/TEAMUSB/code/mbed_SPISlave_LPC/#ef81d9e62dce