

The MCP23S17 is a 16-bit I/O expander that communicates via the SPI (Serial Peripheral Interface) protocol. It is designed to provide additional GPIO (General Purpose Input/Output) pins for microcontroller-based applications. This component is highly versatile and can be configured for both input and output operations, making it ideal for projects requiring more I/O pins than what is available on the microcontroller.








The MCP23S17 offers a range of features and specifications that make it a powerful and flexible I/O expander.
The MCP23S17 has 28 pins, with the following key pin assignments:
| Pin | Name | Description |
|---|---|---|
| 1 | A0 | Hardware address pin 0 (used for device addressing on the SPI bus) |
| 2 | A1 | Hardware address pin 1 |
| 3 | A2 | Hardware address pin 2 |
| 4 | RESET | Active-low reset input |
| 5 | CS | Chip Select (active-low) |
| 6 | SCK | SPI Clock |
| 7 | SI | SPI Data Input |
| 8 | SO | SPI Data Output |
| 9-16 | GPA0-GPA7 | General Purpose I/O pins for PORTA |
| 17-24 | GPB0-GPB7 | General Purpose I/O pins for PORTB |
| 25 | INTB | Interrupt output for PORTB (active-low) |
| 26 | INTA | Interrupt output for PORTA (active-low) |
| 27 | VSS | Ground |
| 28 | VDD | Power supply (1.8V to 5.5V) |
The MCP23S17 is straightforward to use in a circuit. Below are the steps and considerations for integrating it into your project.
Below is an example of how to use the MCP23S17 with an Arduino UNO to toggle an LED connected to GPA0.
#include <SPI.h>
// MCP23S17 SPI settings
#define CS_PIN 10 // Chip Select pin for MCP23S17
#define OPCODE 0x40 // MCP23S17 opcode (A2, A1, A0 = 0)
// MCP23S17 register addresses
#define IODIRA 0x00 // I/O direction register for PORTA
#define OLATA 0x14 // Output latch register for PORTA
void setup() {
pinMode(CS_PIN, OUTPUT); // Set CS pin as output
digitalWrite(CS_PIN, HIGH); // Set CS pin high (inactive)
SPI.begin(); // Initialize SPI
SPI.setClockDivider(SPI_CLOCK_DIV4); // Set SPI clock speed (4 MHz for Arduino UNO)
// Configure GPA0 as output
writeRegister(IODIRA, 0xFE); // Set GPA0 as output, others as input
}
void loop() {
// Toggle GPA0
writeRegister(OLATA, 0x01); // Set GPA0 high
delay(500); // Wait 500 ms
writeRegister(OLATA, 0x00); // Set GPA0 low
delay(500); // Wait 500 ms
}
// Function to write to MCP23S17 register
void writeRegister(byte reg, byte value) {
digitalWrite(CS_PIN, LOW); // Select MCP23S17
SPI.transfer(OPCODE); // Send opcode
SPI.transfer(reg); // Send register address
SPI.transfer(value); // Send data
digitalWrite(CS_PIN, HIGH); // Deselect MCP23S17
}
No Response from MCP23S17:
Incorrect GPIO Behavior:
Interrupts Not Working:
Q: Can I use multiple MCP23S17 devices on the same SPI bus?
A: Yes, up to 8 devices can be used by configuring the A0, A1, and A2 address pins.
Q: What is the maximum current the MCP23S17 can handle?
A: Each pin can source or sink up to 25 mA, with a total maximum current of 125 mA per port.
Q: Do I need external pull-up resistors for the GPIO pins?
A: Pull-up resistors are required for input pins if the connected device does not provide them.
This concludes the documentation for the MCP23S17.