MCP23S17 Test

Dependencies:   MCP23S17 mbed mbed-rtos

Revision:
0:5610193796b3
Child:
1:5321e8f5b339
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 28 05:41:48 2016 +0000
@@ -0,0 +1,46 @@
+/*
+ * MCP23S17 Test
+ *
+ * https://developer.mbed.org/users/romilly/code/MCP23S17/
+ *
+ * Created: 2016.10.28
+ *
+ */
+
+#include "mbed.h"
+#include "MCP23S17.h"
+
+#define OPCODE (0x40)
+
+SPI Spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
+
+// MCP23S17(SPI& spi, PinName ncs, char writeOpcode);
+MCP23S17 Mcp23s17(Spi, PB_6, OPCODE);
+
+int main()
+{
+    printf("\r\n\n*** MCP23S17 Test ***\r\n");
+
+    // PORTA output
+    Mcp23s17.direction(PORT_A, 0x00);
+
+    // PORTB input
+    Mcp23s17.direction(PORT_B, 0xFF);
+    // PORTB pull-up
+    Mcp23s17.configurePullUps(PORT_B, 0xFF);
+    
+    // LED Check
+    for (int i = 0; i < 8; i++) {
+        Mcp23s17.write(PORT_A, (1 << i));
+        wait(0.2);
+    }
+    Mcp23s17.write(PORT_A, 0x00);
+    
+    while (true) {
+        char data = ~Mcp23s17.read(PORT_B);
+        Mcp23s17.write(PORT_A, data);
+        
+        printf("%02x\r\n", data);
+    }
+}
+