A simple IO demo using the MCP23S17 library
Demo for Microchip MCP23S17 16-bit SPI I/O expander chip on mbed LPC1768 using hardware SPI functions. See comments in main.cpp for pin usage. This chip is still available in a DIP package, so it is easy to try on a breadboard. A complete datasheet for the Microchip MCP23SA17 SPI I/O port expander chip can be found at http://ww1.microchip.com/downloads/en/DeviceDoc/20001952c.pdf
Import programMCP23S17_Basic_IO_Demo
A simple IO demo using the MCP23S17 library
Diff: main.cpp
- Revision:
- 2:934a0500abde
- Parent:
- 1:70e1ebe47253
diff -r 70e1ebe47253 -r 934a0500abde main.cpp
--- a/main.cpp Fri Jan 28 01:44:27 2011 +0000
+++ b/main.cpp Fri Jan 28 02:04:05 2011 +0000
@@ -1,29 +1,34 @@
-/* A simple IO demo using 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/
-*
+// A simple IO demo using the MCP23S17 library
+//
+// 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/
+//
+//
+// MCP23S17 datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
+// uses MCP23S17 library version 0.4
-* MCP23S17 datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
-* version 0.4
-*/
#include "mbed.h"
#include "MCP23S17.h"
-
+// Create SPI bus
SPI spi(p5, p6, p7);
-// Create SPI bus
+//
+// Wiring Connections:
// mbed p5,p6,p7 are tied to MCP23S17 SI, SO, SCK pins
+// mbed p20 to MCP23S17 CS
+// MCP23S17 reset pin pulled high
+// MCP23S17 GPA0 connected to GPB0 for loopback test
// A0, A1, A2 of the MCP23S17 are tied to ground on the breadboard, so the 8-bit address for writes is 0x40
// This is referred to as the opcode in the device datasheet
-char writeOpcode = 0x40;
+char Opcode = 0x40;
// Next create a MCP23S17
// mbed p20 is connected to ~chipSelect on the MCP23S17
-MCP23S17 chip = MCP23S17(spi, p20, writeOpcode);
+MCP23S17 chip = MCP23S17(spi, p20, Opcode);
-// Optional software reset - mbed p20 to MCP23S17 reset pin
-// DigitalOut reset(p20);
+// Optional software reset - mbed p14 to MCP23S17 reset pin
+// DigitalOut reset(p14);
DigitalOut led1(LED1); // mbed LED1 is used for test status display
@@ -56,6 +61,6 @@
wait(.5);
// read back value from MCP23S17 Port B and display B0 on mbed led1
led1 = chip.read(PORT_B)& 0x01;
- // led1 should blink slowly if it is all working
+ // led1 should blink slowly when it is all working
}
}

MCP23S17 I/O Expander