The MCP23S17 is a 16-bit I/O expander with an SPI (Serial Peripheral Interface) communication interface. It is designed to expand the number of GPIO (General Purpose Input/Output) pins available in microcontroller-based applications. The device features two 8-bit ports (PORTA and PORTB), which can be individually configured as input or output. Additionally, it supports interrupt-on-change functionality, making it ideal for applications requiring event-driven input monitoring.
Explore Projects Built with MCP23S17
Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
This circuit appears to be a control system utilizing two MCP23017 I/O expanders interfaced with an Olimex ESP32-EVB microcontroller via I2C communication, as indicated by the SDA and SCL connections with pull-up resistors. The MCP23017 expanders control an 8-channel relay module, allowing the microcontroller to switch various loads, potentially for home automation or industrial control. Additionally, there is an Adafruit ADS1115 16-bit ADC for analog signal measurement, and several heating actuators and a thermostat are connected, suggesting temperature control functionality.
This circuit features two MCP23017 I/O expanders interfaced with multiple switches, allowing for the expansion of input capabilities. The MCP23017s are connected via I2C to an Olimex ESP32-EVB microcontroller, which likely manages the input states from the switches. Additionally, an Adafruit ADS1115 16-bit ADC is included, suggesting that some analog inputs are being monitored, with the ADC also interfaced with the ESP32 via I2C.
This circuit is designed to control an 8-channel relay module via an ESP8266 microcontroller, which interfaces with an MCP23017 I/O expander over I2C. The ESP8266 connects to a WiFi network and subscribes to MQTT topics to receive commands for toggling the relays. Additionally, there are toggle switches connected to the MCP23017 that allow manual control of the relays, with the system's state being reported back via MQTT.
This circuit is a WiFi-enabled relay control system using an ESP8266-01 module and an MCP23017 I/O expander. The ESP8266 communicates with the MCP23017 via I2C to control an 8-channel relay module based on the state of 8 rocker switches, allowing for remote and manual control of connected devices.
The MCP23S17 is a versatile and robust I/O expander. Below are its key technical details:
Parameter
Value
Operating Voltage (VDD)
1.8V to 5.5V
Communication Interface
SPI (up to 10 MHz)
GPIO Pins
16 (split into two 8-bit ports)
GPIO Voltage Levels
0V to VDD
Interrupt Pins
2 (INTA, INTB)
Maximum Sink Current
25 mA per pin
Maximum Source Current
25 mA per pin
Package Options
PDIP, SOIC, SSOP, QFN
Operating Temperature
-40°C to +125°C
Pin Configuration and Descriptions
The MCP23S17 has 28 pins. Below is the pinout and description:
Pin Number
Pin Name
Description
1
GPB0
GPIO Port B, Bit 0
2
GPB1
GPIO Port B, Bit 1
3
GPB2
GPIO Port B, Bit 2
4
GPB3
GPIO Port B, Bit 3
5
GPB4
GPIO Port B, Bit 4
6
GPB5
GPIO Port B, Bit 5
7
GPB6
GPIO Port B, Bit 6
8
GPB7
GPIO Port B, Bit 7
9
VSS
Ground (0V)
10
INTB
Interrupt output for Port B
11
INTA
Interrupt output for Port A
12
SCL/SCK
SPI Clock Input
13
SDA/SDI
SPI Data Input
14
A0
Address Pin 0 (used for device addressing)
15
A1
Address Pin 1 (used for device addressing)
16
A2
Address Pin 2 (used for device addressing)
17
RESET
Active-low Reset Input
18
CS
Chip Select (Active Low)
19
SDO
SPI Data Output
20
VDD
Power Supply (1.8V to 5.5V)
21
GPA7
GPIO Port A, Bit 7
22
GPA6
GPIO Port A, Bit 6
23
GPA5
GPIO Port A, Bit 5
24
GPA4
GPIO Port A, Bit 4
25
GPA3
GPIO Port A, Bit 3
26
GPA2
GPIO Port A, Bit 2
27
GPA1
GPIO Port A, Bit 1
28
GPA0
GPIO Port A, Bit 0
Usage Instructions
The MCP23S17 is straightforward to use in SPI-based systems. Below are the steps and considerations for integrating it into your circuit:
Connecting the MCP23S17
Power Supply: Connect the VDD pin to a power source (1.8V to 5.5V) and the VSS pin to ground.
SPI Interface: Connect the SCL/SCK, SDA/SDI, and SDO pins to the SPI clock, data input, and data output lines of your microcontroller, respectively.
Chip Select: Connect the CS pin to a GPIO pin on your microcontroller to enable/disable communication with the MCP23S17.
Address Pins: Configure the A0, A1, and A2 pins to set the device address (useful when multiple MCP23S17 devices are on the same SPI bus).
GPIO Pins: Connect the GPAx and GPBx pins to your desired peripherals (e.g., LEDs, switches, sensors).
Interrupts: Optionally, connect the INTA and INTB pins to monitor interrupt events.
Configuring the MCP23S17
The MCP23S17 is configured by writing to its internal registers via SPI. Below is an example of how to configure the device using an Arduino UNO:
#include <SPI.h>
// Define MCP23S17 SPI settings
#define MCP23S17_CS 10 // Chip Select pin for MCP23S17
#define IOCON 0x0A // IOCON register address
#define IODIRA 0x00 // I/O Direction register for Port A
#define IODIRB 0x01 // I/O Direction register for Port B
#define GPIOA 0x12 // GPIO register for Port A
#define GPIOB 0x13 // GPIO register for Port B
void setup() {
pinMode(MCP23S17_CS, OUTPUT);
digitalWrite(MCP23S17_CS, HIGH); // Set CS high to disable MCP23S17
SPI.begin(); // Initialize SPI
// Configure MCP23S17
digitalWrite(MCP23S17_CS, LOW); // Select MCP23S17
SPI.transfer(0x40); // Write opcode (0x40 = write, address = 0)
SPI.transfer(IOCON); // Select IOCON register
SPI.transfer(0x28); // Set IOCON (e.g., enable hardware addressing)
digitalWrite(MCP23S17_CS, HIGH); // Deselect MCP23S17
// Set Port A as output and Port B as input
digitalWrite(MCP23S17_CS, LOW);
SPI.transfer(0x40); // Write opcode
SPI.transfer(IODIRA); // Select IODIRA register
SPI.transfer(0x00); // Set all Port A pins as output
digitalWrite(MCP23S17_CS, HIGH);
digitalWrite(MCP23S17_CS, LOW);
SPI.transfer(0x40); // Write opcode
SPI.transfer(IODIRB); // Select IODIRB register
SPI.transfer(0xFF); // Set all Port B pins as input
digitalWrite(MCP23S17_CS, HIGH);
}
void loop() {
// Example: Toggle Port A pins
digitalWrite(MCP23S17_CS, LOW);
SPI.transfer(0x40); // Write opcode
SPI.transfer(GPIOA); // Select GPIOA register
SPI.transfer(0xFF); // Set all Port A pins high
digitalWrite(MCP23S17_CS, HIGH);
delay(500);
digitalWrite(MCP23S17_CS, LOW);
SPI.transfer(0x40); // Write opcode
SPI.transfer(GPIOA); // Select GPIOA register
SPI.transfer(0x00); // Set all Port A pins low
digitalWrite(MCP23S17_CS, HIGH);
delay(500);
}
Best Practices
Use pull-up or pull-down resistors on GPIO pins to ensure stable logic levels.
Decouple the power supply with a 0.1 µF capacitor near the VDD pin.
Avoid exceeding the maximum current ratings to prevent damage to the device.
Troubleshooting and FAQs
Common Issues
No Response from MCP23S17:
Ensure the CS pin is correctly toggled during SPI communication.
Verify the SPI clock speed does not exceed 10 MHz.
Check the wiring of the SPI lines (SCK, SDI, SDO).
Interrupts Not Triggering:
Confirm that the interrupt-on-change feature is enabled in the configuration registers.
Ensure the INTA/INTB pins are connected to the microcontroller.
Incorrect GPIO Behavior:
Verify the IODIRA and IODIRB registers are correctly configured for input/output.
Check for loose or incorrect connections on the GPIO pins.
FAQs
Q: Can I use multiple MCP23S17 devices on the same SPI bus?
A