MCP23S17 Test
Dependencies: MCP23S17 mbed mbed-rtos
Revision 3:42a3ae578926, committed 2016-10-30
- Comitter:
- ryood
- Date:
- Sun Oct 30 07:19:46 2016 +0000
- Parent:
- 2:c8c30a78bbb3
- Commit message:
- Change the MCP23S17 Library to https://developer.mbed.org/users/stjo2809/code/MCP23S17/; Impl. Interrupt;
Changed in this revision
MCP23S17.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MCP23S17.lib Fri Oct 28 06:57:55 2016 +0000 +++ b/MCP23S17.lib Sun Oct 30 07:19:46 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/romilly/code/MCP23S17/#068b1e8909bb +http://mbed.org/users/stjo2809/code/MCP23S17/#b2a44e1e54b8
--- a/main.cpp Fri Oct 28 06:57:55 2016 +0000 +++ b/main.cpp Sun Oct 30 07:19:46 2016 +0000 @@ -1,7 +1,8 @@ /* * MCP23S17 Test * - * https://developer.mbed.org/users/romilly/code/MCP23S17/ + * MCP23S17 Library: + * https://developer.mbed.org/users/stjo2809/code/MCP23S17/ * * mbed: rev 121 * mbed-rtos: rev 117 @@ -14,38 +15,51 @@ #include "rtos.h" #include "MCP23S17.h" -#define OPCODE (0x40) - SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk //SPI Spi(PA_7, PA_6, PA_5); // SPI1: mosi, miso, sclk -// MCP23S17(SPI& spi, PinName ncs, char writeOpcode); -MCP23S17 Mcp23s17(Spi, PD_2, OPCODE); +InterruptIn Mcp23s17Int(PA_14); + +// MCP23S17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset); +MCP23S17 Mcp23s17(0x00, Spi, PD_2, PA_13); + +void dataChanged() +{ + char data = Mcp23s17.intcapb(); + wait_us(1); + Mcp23s17.gpioa(data); +} int main() { printf("\r\n\n*** MCP23S17 Test ***\r\n"); + // Reset MCP23S17 + Mcp23s17.reset(); + // PORTA output - Mcp23s17.direction(PORT_A, 0x00); + Mcp23s17.iodira(0x00); // PORTB input - Mcp23s17.direction(PORT_B, 0xFF); + Mcp23s17.iodirb(0xFF); // PORTB pull-up - Mcp23s17.configurePullUps(PORT_B, 0xFF); + Mcp23s17.gppub(0xFF); + // PORTB invert polarity + Mcp23s17.ipolb(0xFF); + // PORTB enable on change interrupt + Mcp23s17.gpintenb(0xFF); + + // Attach the callback function + Mcp23s17Int.rise(&dataChanged); // LED Check for (int i = 0; i < 8; i++) { - Mcp23s17.write(PORT_A, (1 << i)); - wait(0.2); + Mcp23s17.gpioa(1 << i); + wait(0.1); } - Mcp23s17.write(PORT_A, 0x00); + Mcp23s17.gpioa(0x00); while (true) { - char data = ~Mcp23s17.read(PORT_B); - Mcp23s17.write(PORT_A, data); - - //printf("%02x\r\n", data); } }