ec

Dependencies:   MCP23S17 mbed

Fork of 4180_lab1_part7 by 4180

Files at this revision

API Documentation at this revision

Comitter:
Josahty
Date:
Mon Jan 22 18:34:48 2018 +0000
Parent:
0:8efa2ed1bc48
Commit message:
ec

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jan 19 20:49:13 2018 +0000
+++ b/main.cpp	Mon Jan 22 18:34:48 2018 +0000
@@ -21,17 +21,19 @@
 // MCP23S17 GPA0 connected to GPB0 for loopback test
 // A0, A1, A2 of the MCP23S17  are tied to ground on the breadboard, so the 8-bit address for writes is 0x40
 // This is referred to as the opcode in the device datasheet
-char Opcode = 0x40;
+char OpcodeA = 0x40;
+char OpcodeB = 0x42;
 
 // Next create a MCP23S17
 // mbed p20 is connected to ~chipSelect on the MCP23S17
-MCP23S17 chip = MCP23S17(spi, p20, Opcode);
+MCP23S17 chip1 = MCP23S17(spi, p20, OpcodeA);
+MCP23S17 chip2 = MCP23S17(spi, p21, OpcodeB);
 
 // Optional software reset - mbed p14 to MCP23S17 reset pin
 // DigitalOut reset(p14);
 
-DigitalOut led1(p29); // mbed LED1 is used for test status display
-DigitalIn pb(p30);
+DigitalOut led1(p22); // mbed LED1 is used for test status display
+DigitalIn pb(p19);
 
 int main() {
 //  The MCP23S17 reset pin can just be pulled high, since it has a power on reset circuit.
@@ -44,29 +46,42 @@
 //  wait_us(1);
 //  reset = 1;
 
-    pb.mode(PullUp);
+    //pb.mode(PullUp);
 
 //  Set all 8 Port A bits to output direction
-    chip.direction(PORT_A, 0x00);
+    chip1.direction(PORT_A, 0x00);
+    chip2.direction(PORT_A, 0x00);
 //  Set all 8 Port B bits to input direction
-    chip.direction(PORT_B, 0xFF);
-    led1=0;
+    chip1.direction(PORT_B, 0xFF);
+    chip2.direction(PORT_B, 0xFF);
 //  Start Loopback test sending out and reading back values
 //  loopback test uses A0 and B0 pins - so use a wire to jumper those two pins on MCP23S17 together
     while (1) {
-        while(pb) {  
-            chip.write(PORT_A, 0x55);
+        if(!(chip1.read(PORT_B) & 0x01)) {  
+            chip1.write(PORT_A, 0x55);
             wait(.1);
             // read back value from MCP23S17 Port B and display B0 on mbed led1
-            led1 = chip.read(PORT_B)& 0x01;
+            //led1 = 1;
         }
         // write 0xAA to MCP23S17 Port A
-        
+        else {
         // write 0x55 to MCP23S17 Port A
-        chip.write(PORT_A, 0xAA);
+        chip1.write(PORT_A, 0xAA);
         wait(.1);
         // read back value from MCP23S17 Port B and display B0 on mbed led1
-        led1 = chip.read(PORT_B)& 0x01;
+        //led1 = 0;
         // led1 should blink slowly when it is all working
+        }
+        
+        if((chip2.read(PORT_B) & 0x01)) {
+            chip2.write(PORT_A, 0x55);
+            wait(0.1);
+            led1 = 1;
+        }
+        else {
+            chip2.write(PORT_A, 0xAA);
+            wait(0.1);
+            led1 = 0;
+        }        
     }
 }