7_2_slave

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jangelgm
Date:
Tue Mar 07 11:33:50 2017 +0000
Commit message:
7_2_slave

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 73793c67337f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 07 11:33:50 2017 +0000
@@ -0,0 +1,41 @@
+ /* Sets the mbed up as Slave, and exchanges data with a Master,
+sending its own switch positions, and displaying those of the Master. as SPI slave
+ */
+#include "mbed.h"
+SPISlave ser_port(p11, p12, p13, p14); //mosi, miso, sclk, ssel
+DigitalOut red_led(p25); //red led
+DigitalOut green_led(p26); //green led
+
+DigitalIn switch_ip1(p5);
+DigitalIn switch_ip2(p6);
+
+char switch_word ; //word we will send
+char recd_val; //value return from slave
+
+ int main() 
+ {
+//default formatting applied
+    while(1) {
+        //set up switch_word from switches that are pressed
+        switch_word=0xa0; //set up a recognizable output pattern
+        if (switch_ip1==1)
+            switch_word=switch_word | 0x01; 
+        if (switch_ip2==1)
+            switch_word=switch_word | 0x02;
+        if(ser_port.receive()) { //test if data transfer has occurred
+            recd_val = ser_port.read(); // Read byte from master
+            ser_port.reply(switch_word); // Make this the next reply
+                            }
+        red_led=0; //preset both to 0
+        green_led=0;
+        recd_val=recd_val & 0x03; //AND out unwanted bits
+        if (recd_val==1)
+            red_led=1;
+        if (recd_val==2)
+            green_led=1;
+        if (recd_val==3){
+            red_led=1;
+            green_led=1;
+                    }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 73793c67337f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 07 11:33:50 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file