ece4180 lab1

Dependencies:   MCP23S17 mbed

Fork of MCP23S17_Basic_IO_Demo by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
boalinlai
Date:
Wed Sep 07 15:30:55 2016 +0000
Parent:
2:934a0500abde
Child:
4:a361b0d3aaaf
Commit message:
lab1 extra credit;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jan 28 02:04:05 2011 +0000
+++ b/main.cpp	Wed Sep 07 15:30:55 2016 +0000
@@ -26,6 +26,7 @@
 // Next create a MCP23S17
 // mbed p20 is connected to ~chipSelect on the MCP23S17
 MCP23S17 chip = MCP23S17(spi, p20, Opcode);
+MCP23S17 chip2 = MCP23S17(spi, p19, Opcode);
 
 // Optional software reset - mbed p14 to MCP23S17 reset pin
 // DigitalOut reset(p14);
@@ -44,23 +45,38 @@
 //  reset = 1;
 //
 //  Set all 8 Port A bits to output direction
-    chip.direction(PORT_A, 0x00);
+    chip.direction(PORT_A, 0xFF);
 //  Set all 8 Port B bits to input direction
-    chip.direction(PORT_B, 0xFF);
+    chip.direction(PORT_B, 0x00);
+    
+    // second chip
+     chip2.direction(PORT_A, 0x00);
+//  Set all 8 Port B bits to input direction
+    chip2.direction(PORT_B, 0xFF);
+    
+    
     led1=0;
 //  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) {
         // write 0xAA to MCP23S17 Port A
-        chip.write(PORT_A, 0xAA);
-        wait(.5);
+        //if( < 0.1)
+        //{
+           chip.write(PORT_B, 0x01 & (chip2.read(PORT_B) &0x01));
+             //wait(0.05);
+        //}
+        /*else
+        {
         // read back value from MCP23S17 Port B and display B0 on mbed led1
-        led1 = chip.read(PORT_B)& 0x01;
+        //led1 = chip.read(PORT_B)& 0x01;
         // write 0x55 to MCP23S17 Port A
-        chip.write(PORT_A, 0x55);
-        wait(.5);
+        chip.write(PORT_B, 0x1);
+        }*/
+
+        led1 = chip.read(PORT_A)& 0x01;
         // read back value from MCP23S17 Port B and display B0 on mbed led1
-        led1 = chip.read(PORT_B)& 0x01;
+        //led1 = chip.read(PORT_B)& 0x01;
+         wait(0.05);
         // led1 should blink slowly when it is all working
     }
 }