Library test v 0.4

Dependencies:   mbed MCP23S17

Files at this revision

API Documentation at this revision

Comitter:
romilly
Date:
Sat Aug 21 14:49:00 2010 +0000
Child:
1:d7fe22a24841
Commit message:

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP23S17.lib	Sat Aug 21 14:49:00 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/romilly/code/MCP23S17/#068b1e8909bb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 21 14:49:00 2010 +0000
@@ -0,0 +1,35 @@
+/* Test drive the MCP23S17 library
+* Copyright (c) 2010 Romilly Cocking
+* Released under the MIT License: http://mbed.org/license/mit
+* See http://mbed.org/users/romilly/notebook/mcp23s17-addressable-16-bit-io-expander-with-spi/
+*/
+#include "mbed.h"
+#include "MCP23S17.h"
+
+SPI spi(p5, p6, p7);
+
+char writeOpcode = 0x40; // A0, A1, A2 are tied to ground on the breadboard.
+MCP23S17 chip = MCP23S17(spi, p20, 0x40);
+DigitalOut chipA0(p12);
+DigitalIn  chipB0(p10);
+
+void checkEqual(int expected, int actual, char * text) {
+    if (expected != actual) {
+        printf("%s **TEST FAILED** - expected %i but get %i", text, expected, actual);
+        exit(-1);
+    }
+}
+
+int main() {
+    for (int i = 0; i < 100; i++) {
+        chip.directionA(0xFF); // all 8 bits set to input
+        chip.directionB(0xFE); // bit 0 set to output
+        chipA0 = 1;
+        // copy input bit 0 from A to output bit 0 on B
+        chip.outputB(chip.inputA() && 1);
+        checkEqual(1, int(chipB0),"copying 1 from A0 to B0");
+        // copy input bit 0 from A to output bit 0 on B
+        chip.outputB(chip.inputA() && 1);
+        checkEqual(1, int(chipB0), "copying 0 from A0 to B0");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Aug 21 14:49:00 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da