- Published: Friday, 23 April 2010
- Written by LightSpeed334
- Hits: 7810
After a recent discussion on the forum regarding shift registers, I thought I would share what I have done with the feedback from others.
Whats a MCP23S17?
Its a 16-Bit I/O Expander with Serial Interface. In other words, it extends the number of logic I/O's available to a micro controller (handy for driving a large number of LEDs for example!).
A quick overview of features from the MCP23S17 Datasheet:
- 16-bit remote bidirectional I/O port
- I/O pins default to input
- High-speed SPI interface (MCP23S17)
- 10 MHz (max.)
- Three hardware address pins to allow up to eight devices on the bus
- Configurable interrupt output pins
- Configurable as active-high, active-low or open-drain
- Maximum output current sourced or sunk by any output pin ... 25mA
- Maximum current out of VSS pin ... 150mA
- Maximum current into VDD pin ... 125mA
- Configurable interrupt source
- Interrupt-on-change from configured register defaults or pin changes
- Low standby current: 1 μA (max.)
- Operating voltage:
- 1.8V to 5.5V @ -40°C to +85°C
Although the device is capable of driving +/-25mA on each pin, it is restricted to the maximum collective current as shown in the list above (~150mA). In terms of comparison with other devices I have found on the net, this "limitation" is of minor concern and trumps 95% of other shift registers.
The user module (linked further down) allows a combined update speed of ~17uS for all 16 outputs (~60Khz). Is this a limitation? In terms of functionality its a consideration, not a show stopper. Most persistence of vision projects with LOTS of LEDs need a refresh rate of ~25Hz (which is 2400% less then what these devices can deliver).
There can only be 8 different device addresses. This limits the total number of I/Os to 128 (8 * 16).
Schematic (Multiple Devices)
(I was interested to see how much time it took to update all 32 outputs, hence the frequency meter. As it turns out, this happens
at ~30Khz with a PIC configured to run at 40Mhz)
Swordfish User Module
Can be downloaded here - User Module Pack (MCP23S17_MULT.bas)
Before compiling the example programs - you will need to update SPI.bas as explained by Graham in this post (if you are using a PIC with SPI errata).
Here's a program that will increment a LongWord type variable and display each of the 4 bytes on a separate port - in an infinite loop.
Here's another example program that configures one port as all inputs (also enables internal pullup resistors), and the other port as all outputs. The output port will then mirror the input port.