Learning About Arduino with MCP23S08
These are my notes about interfacing the MCP23S08 with an Arduino Diecimila.
Note: VDD = positive supply, VSS = ground (see)
- Arduino/MCP23S08 Breadboard circuit (PDF) (PNG) (SVG "Inkscape" dialect--probably won't render correctly in Firefox)
- Initial code that reads GPIO and prints to serial: http://code.rancidbacon.com/files/MCP23S08_a.pde
- Update to code that also sets pins as outputs and writes to them: http://code.rancidbacon.com/files/MCP23S08_l.pde (Demo assumes a push-button wired to bit-0 and four LEDs wired bit-7 thru bit-4.)
Notes from MCP23S08 datasheet
- Address pins (A0, A1): "the pins must be biased externally".
- "I/O pins default to input"
- "High-speed SPI interface (MCP23S08) - 10MHz"
- "18.104.22.168 SPI Read Operation The SPI Read operation is started by lowering CS. The SPI read command (slave address with R/W bit set) is then clocked into the device. The opcode is followed by an address, with at least one data byte being clocked out of the device."
- "22.214.171.124 SPI Write Operation The SPI Write operation is started by lowering CS. The Write command (slave address with R/W bit cleared) is then clocked into the device. The opcode is followed by an address and at least one data byte."
- "1.4.2 ADDRESSING SPI DEVICES (MCP23S08) The MCP23S08 is a slave SPI device. The slave address contains five fixed bits and two user-defined hardware address bits (pins A1 and A0), with the read/ write bit filling out the control byte. Figure 1-3 shows the control byte format"
Note that the following diagrams have the data flowing in the same direction with respect to the diagram which is the opposite to how it actually works in real life. @@ TODO explain this better. (This difference is significant when determining if the MSB (Most Significant Bit) is being transmitted first or not.)
Notes from Atmega168 datasheet
- "SPCR – SPI Control Register"
- Application Note: Unique Features of the MCP23X08/17 GPIO Expanders -- includes reference to address pins
- I/O Expansion Using the MCP23X08 and PIC10F202 -- includes schematics with address pins
- Example circuit with MCP23008 -- seems to include biasing the address pins.
@@ TODO: Finish this