v 0.4

Dependents:   MCP23S17Test MCP23S17_Basic_IO_Demo HelloWorld Lab3-SnakeGame ... more

Revision:
2:6144709f1700
Child:
3:089a2a754567
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP23S17.h	Sat Aug 21 14:46:59 2010 +0000
@@ -0,0 +1,47 @@
+/* MCP23S17 - drive the Microchip MCP23S17 16-bit Port Extender using SPI
+* Copyright (c) 2010 Romilly Cocking
+* Released under the MIT License: http://mbed.org/license/mit
+*
+* version 0.1
+*/
+#include "mbed.h"
+
+#ifndef  SER23K256_H
+#define  SER23K256_H
+
+// all register addresses assume IOVCON.BANK = 0 (POR default)
+
+#define IODIRA 0x00
+#define IODIRB 0x01
+#define IOCON  0x0A
+#define GPIOA  0x12
+#define GPIOB  0x13
+#define OLATA  0x14
+#define OLATB  0x15
+
+// Control settings
+
+#define IOCON_BANK  0x80 // Banked registers
+#define IOCON_BYTE_MODE 0x20 // Disables sequential operation. If bank = 0, operations toggle between A and B registers
+#define IOCON_HAEN  0x08 // Hardware address enable
+
+class MCP23S17 {
+public:
+    MCP23S17(SPI& spi, PinName ncs, char writeOpcode);
+    void directionA(char direction);
+    void directionB(char direction);
+    char inputA();
+    char inputB();
+    void outputA(char byte);
+    void outputB(char byte);
+protected:
+    SPI& _spi;
+    DigitalOut _ncs;
+    void _init();
+    void _write(char address, char data);
+    char _read(char address);
+    char _readOpcode;
+    char _writeOpcode;
+};
+
+#endif
\ No newline at end of file