MCP23S17 Test
Dependencies: MCP23S17 mbed mbed-rtos
main.cpp@2:c8c30a78bbb3, 2016-10-28 (annotated)
- Committer:
- ryood
- Date:
- Fri Oct 28 06:57:55 2016 +0000
- Revision:
- 2:c8c30a78bbb3
- Parent:
- 1:5321e8f5b339
- Child:
- 3:42a3ae578926
Change: mbed:rev.121 mbed-rtos:rev.117
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryood | 0:5610193796b3 | 1 | /* |
ryood | 0:5610193796b3 | 2 | * MCP23S17 Test |
ryood | 0:5610193796b3 | 3 | * |
ryood | 0:5610193796b3 | 4 | * https://developer.mbed.org/users/romilly/code/MCP23S17/ |
ryood | 0:5610193796b3 | 5 | * |
ryood | 2:c8c30a78bbb3 | 6 | * mbed: rev 121 |
ryood | 2:c8c30a78bbb3 | 7 | * mbed-rtos: rev 117 |
ryood | 2:c8c30a78bbb3 | 8 | * |
ryood | 0:5610193796b3 | 9 | * Created: 2016.10.28 |
ryood | 0:5610193796b3 | 10 | * |
ryood | 0:5610193796b3 | 11 | */ |
ryood | 0:5610193796b3 | 12 | |
ryood | 0:5610193796b3 | 13 | #include "mbed.h" |
ryood | 1:5321e8f5b339 | 14 | #include "rtos.h" |
ryood | 0:5610193796b3 | 15 | #include "MCP23S17.h" |
ryood | 0:5610193796b3 | 16 | |
ryood | 0:5610193796b3 | 17 | #define OPCODE (0x40) |
ryood | 0:5610193796b3 | 18 | |
ryood | 2:c8c30a78bbb3 | 19 | SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk |
ryood | 2:c8c30a78bbb3 | 20 | //SPI Spi(PA_7, PA_6, PA_5); // SPI1: mosi, miso, sclk |
ryood | 0:5610193796b3 | 21 | |
ryood | 0:5610193796b3 | 22 | // MCP23S17(SPI& spi, PinName ncs, char writeOpcode); |
ryood | 1:5321e8f5b339 | 23 | MCP23S17 Mcp23s17(Spi, PD_2, OPCODE); |
ryood | 0:5610193796b3 | 24 | |
ryood | 0:5610193796b3 | 25 | int main() |
ryood | 0:5610193796b3 | 26 | { |
ryood | 0:5610193796b3 | 27 | printf("\r\n\n*** MCP23S17 Test ***\r\n"); |
ryood | 0:5610193796b3 | 28 | |
ryood | 0:5610193796b3 | 29 | // PORTA output |
ryood | 0:5610193796b3 | 30 | Mcp23s17.direction(PORT_A, 0x00); |
ryood | 0:5610193796b3 | 31 | |
ryood | 0:5610193796b3 | 32 | // PORTB input |
ryood | 0:5610193796b3 | 33 | Mcp23s17.direction(PORT_B, 0xFF); |
ryood | 0:5610193796b3 | 34 | // PORTB pull-up |
ryood | 0:5610193796b3 | 35 | Mcp23s17.configurePullUps(PORT_B, 0xFF); |
ryood | 0:5610193796b3 | 36 | |
ryood | 0:5610193796b3 | 37 | // LED Check |
ryood | 0:5610193796b3 | 38 | for (int i = 0; i < 8; i++) { |
ryood | 0:5610193796b3 | 39 | Mcp23s17.write(PORT_A, (1 << i)); |
ryood | 0:5610193796b3 | 40 | wait(0.2); |
ryood | 0:5610193796b3 | 41 | } |
ryood | 0:5610193796b3 | 42 | Mcp23s17.write(PORT_A, 0x00); |
ryood | 2:c8c30a78bbb3 | 43 | |
ryood | 0:5610193796b3 | 44 | while (true) { |
ryood | 0:5610193796b3 | 45 | char data = ~Mcp23s17.read(PORT_B); |
ryood | 0:5610193796b3 | 46 | Mcp23s17.write(PORT_A, data); |
ryood | 0:5610193796b3 | 47 | |
ryood | 1:5321e8f5b339 | 48 | //printf("%02x\r\n", data); |
ryood | 0:5610193796b3 | 49 | } |
ryood | 0:5610193796b3 | 50 | } |
ryood | 0:5610193796b3 | 51 |