Zhen Liu
/
HW1_extraE
Extra problem 5 for HW 1
Fork of MCP23S17_Basic_IO_Demo by
Revision 3:07745b21792d, committed 2015-02-18
- Comitter:
- lzzcd001
- Date:
- Wed Feb 18 14:49:26 2015 +0000
- Parent:
- 2:934a0500abde
- Commit message:
- Extra problem 5 for HW 1
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 Feb 18 14:49:26 2015 +0000 @@ -13,6 +13,8 @@ #include "MCP23S17.h" // Create SPI bus SPI spi(p5, p6, p7); +DigitalOut a(p21); + // // Wiring Connections: // mbed p5,p6,p7 are tied to MCP23S17 SI, SO, SCK pins @@ -22,10 +24,12 @@ // 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 OpcodeIn = 0x42; // Next create a MCP23S17 // mbed p20 is connected to ~chipSelect on the MCP23S17 MCP23S17 chip = MCP23S17(spi, p20, Opcode); +MCP23S17 chip2 = MCP23S17(spi, p20, OpcodeIn); // Optional software reset - mbed p14 to MCP23S17 reset pin // DigitalOut reset(p14); @@ -33,6 +37,7 @@ DigitalOut led1(LED1); // mbed LED1 is used for test status display int main() { + a = 1; // The MCP23S17 reset pin can just be pulled high, since it has a power on reset circuit. // The reset pin can be used for a software forced reset by pulling it low with an mbed GPIO pin. // But just leave it pulled high for this simple demo code. @@ -47,20 +52,24 @@ chip.direction(PORT_A, 0x00); // Set all 8 Port B bits to input direction chip.direction(PORT_B, 0xFF); + chip2.direction(PORT_A, 0x00); + chip2.direction(PORT_B, 0xFF); led1=0; + int mid = 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); + mid = chip.read(PORT_B) & 0x01; + wait(.1); + chip.write(PORT_A, mid); // read back value from MCP23S17 Port B and display B0 on mbed led1 - led1 = chip.read(PORT_B)& 0x01; + wait(.1); + mid = chip2.read(PORT_B); + wait(.1); // write 0x55 to MCP23S17 Port A - chip.write(PORT_A, 0x55); - wait(.5); - // read back value from MCP23S17 Port B and display B0 on mbed led1 - led1 = chip.read(PORT_B)& 0x01; + chip2.write(PORT_A, mid); + wait(.1); // led1 should blink slowly when it is all working } }