The MCP23017/MCP23S17 (MCP23X17) device
family provides 16-bit, general purpose parallel I/O
expansion for I
devices differ only in the serial interface.
• MCP23017 – I
• MCP23S17 – SPI interface
The MCP23X17 consists of multiple 8-bit configuration
registers for input, output and polarity selection. The
system master can enable the I/Os as either inputs or
outputs by writing the I/O configuration bits (IODIRA/B).
The data for each input or output is kept in the
corresponding input or output register. The polarity of
the Input Port register can be inverted with the Polarity
Inversion register. All registers can be read by the
system master.
The 16-bit I/O port functionally consists of two 8-bit
ports (PORTA and PORTB). The MCP23X17 can be
configured to operate in the 8-bit or 16-bit modes via
IOCON.BANK.
2
C bus or SPI applications. The two
2
C interface
There are two interrupt pins, INTA and INTB, that can
be associated with their respective ports, or can be
logically OR’ed together so that both pins will activate if
either port causes an interrupt.
The interrupt output can be configured to activate
under two conditions (mutually exclusive):
1. When any input state differs from its
corresponding Input Port register state. This is
used to indicate to the system master that an
input state has changed.
2.When an input state differs from a preconfigured
register value (DEFVAL register).
The Interrupt Capture register captures port values at
the time of the interrupt, thereby saving the condition
that caused the interrupt.
The Power-on Reset (POR) sets the registers to their
default values and initializes the device state machine.
The hardware address pins are used to determine the
device address.
GPB0125I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB1226I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB2327I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB3428I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB451I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB562I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB673I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPB784I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
V
DD
V
SS
NC/CS
SCL/SCK128ISerial clock input
SDA/SI139I/OSerial data I/O (MCP23017), Serial data input (MCP23S17)
NC/SO1410ONC (MCP23017), Serial data out (MCP23S17)
A01511IHardware address pin. Must be externally biased.
A11612IHardware address pin. Must be externally biased.
A21713IHardware address pin. Must be externally biased.
RESET
INTB1915OInterrupt output for PORTB. Can be configured as active-high, active-low or open-drain.
INTA2016OInterrupt output for PORTA. Can be configured as active-high, active-low or open-drain.
GPA02117I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA12218I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA22319I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA32420I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA42521I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA52622I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA62723I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
GPA72824I/OBidirectional I/O pin. Can be enabled for interrupt-on-change and/or internal weak pull-up
The on-chip POR circuit holds the device in reset until
DD has reached a high enough voltage to deactivate
V
the POR circuit (i.e., release the device from reset).
The maximum VDD rise time is specified in Section 2.0“Electrical Characteristics”.
When the device exits the POR condition (releases
reset), device operating parameters (i.e., voltage,
temperature, serial bus frequency, etc.) must be met to
ensure proper operation.
1.3Serial Interface
This block handles the functionality of the I2C
(MCP23017) or SPI (MCP23S17) interface protocol.
The MCP23X17 contains 22 individual registers (11
register pairs) that can be addressed through the Serial
Interface block, as shown in Table 1-2.
The MCP23X17 family has the ability to operate in Byte
mode or Sequential mode (IOCON.SEQOP).
Byte Mode disables automatic Address Pointer
incrementing. When operating in Byte mode, the
MCP23X17 family does not increment its internal
address counter after each byte during the data
transfer. This gives the ability to continually access the
same address by providing extra clocks (without
additional control bytes). This is useful for polling the
GPIO register for data changes or for continually
writing to the output latches.
A special mode (Byte mode with IOCON.BANK = 0)
causes the address pointer to toggle between
associated A/B register pairs. For example, if the BANK
bit is cleared and the Address Pointer is initially set to
address 12h (GPIOA) or 13h (GPIOB), the pointer will
toggle between GPIOA and GPIOB. Note that the
Address Pointer can initially point to either address in
the register pair.
Sequential mode enables automatic address pointer
incrementing. When operating in Sequential mode, the
MCP23X17 family increments its address counter after
each byte during the data transfer. The Address Pointer
automatically rolls over to address 00h after accessing
the last register.
These two modes are not to be confused with single
writes/reads and continuous writes/reads that are
serial protocol sequences. For example, the device
may be configured for Byte mode and the master may
perform a continuous read. In this case, the
MCP23X17 would not increment the Address Pointer
and would repeatedly drive data from the same
location.
1.3.2I2C INTERFACE
1.3.2.1I
The I2C write operation includes the control byte and
register address sequence, as shown in the bottom of
Figure 1-1. This sequence is followed by eight bits of
data from the master and an Acknowledge (ACK) from
the MCP23017. The operation is ended with a Stop (P)
or Restart (SR) condition being generated by the
master.
Data is written to the MCP23017 after every byte
transfer. If a Stop or Restart condition is generated
during a data transfer, the data will not be written to the
MCP23017.
Both “byte writes” and “sequential writes” are
supported by the MCP23017. If Sequential mode is
enabled (IOCON, SEQOP = 0) (default), the
MCP23017 increments its address counter after each
ACK during the data transfer.
I2C Read operations include the control byte sequence,
as shown in the bottom of Figure 1-1. This sequence is
followed by another control byte (including the Start
condition and ACK) with the R/W bit set (R/W = 1). The
MCP23017 then transmits the data contained in the
addressed register. The sequence is ended with the
master generating a Stop or Restart condition.
1.3.2.3I2C Sequential Write/Read
For sequential operations (Write or Read), instead of
transmitting a Stop or Restart condition after the data
transfer, the master clocks the next byte pointed to by
the address pointer (see Section 1.3.1 “Byte Modeand Sequential Mode” for details regarding sequential
operation control).
The sequence ends with the master sending a Stop or
Restart condition.
The MCP23017 Address Pointer will roll over to
address zero after reaching the last register address.
Refer to Figure 1-1.
1.3.3SPI INTERFACE
1.3.3.1SPI 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.3.3.2SPI 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.
1.3.3.3SPI Sequential Write/Read
For sequential operations, instead of deselecting the
device by raising CS, the master clocks the next byte
pointed to by the Address Pointer. (see Section 1.3.1“Byte Mode and Sequential Mode” for details
regarding sequential operation control).
The sequence ends by the raising of CS
The MCP23S17 Address Pointer will roll over to
address zero after reaching the last register address.
* Address pins are enabled/disabled via IOCON.HAEN.
1.4Hardware Address Decoder
The hardware address pins are used to determine the
device address. To address a device, the corresponding address bits in the control byte must match the pin
state. The pins must be biased externally.
1.4.1ADDRESSING I2C DEVICES
(MCP23017)
The MCP23017 is a slave I2C interface device that
supports 7-bit slave addressing, with the read/write bit
filling out the control byte. The slave address contains
four fixed bits and three user-defined hardware
address bits (pins A2, A1 and A0). Figure 1-2 shows
the control byte format.
1.4.2ADDRESSING SPI DEVICES
(MCP23S17)
The MCP23S17 is a slave SPI device. The slave
address contains four fixed bits and three user-defined
hardware address bits (if enabled via IOCON.HAEN)
(pins A2, A1 and A0) with the read/write bit filling out
the control byte. Figure 1-3 shows the control byte
format. The address pins should be externally biased
even if disabled (IOCON.HAEN = 0).
The GPIO module is a general purpose, 16-bit wide,
bidirectional port that is functionally split into two 8-bit
wide ports.
The GPIO module contains the data ports (GPIOn),
internal pull-up resistors and the output latches
(OLATn).
Reading the GPIOn register reads the value on the
port. Reading the OLATn register only reads the
latches, not the actual value on the port.
Writing to the GPIOn register actually causes a write to
the latches (OLATn). Writing to the OLATn register
forces the associated output drivers to drive to the level
in OLATn. Pins configured as inputs turn off the
associated output driver and put it in high-impedance.
TABLE 1-3:SUMMARY OF REGISTERS ASSOCIATED WITH THE GPIO PORTS (BANK = 1)
There are 21 registers associated with the MCP23X17,
as shown in Ta bl e 1 -5 and Ta bl e 1 -6 . The two tables
show the register mapping with the two BANK bit
are associated with PortB. One register (IOCON) is
shared between the two ports. The PortA registers are
identical to the PortB registers, therefore, they will be
referred to without differentiating between the port
designation (i.e., they will not have the “A” or “B”
designator assigned) in the register tables.
values. Ten registers are associated with PortA and ten
This register allows the user to configure the polarity on
the corresponding GPIO port bits.
If a bit is set, the corresponding GPIO register bit will
reflect the inverted value on the pin.
REGISTER 1-2:IPOL – INPUT POLARITY PORT REGISTER (ADDR 0x01)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
IP7IP6IP5IP4IP3IP2IP1IP0
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7-0IP7:IP0: These bits control the polarity inversion of the input pins <7:0>
1 = GPIO register bit will reflect the opposite logic state of the input pin.
0 = GPIO register bit will reflect the same logic state of the input pin.
The GPINTEN register controls the interrupt-onchange feature for each pin.
If a bit is set, the corresponding pin is enabled for
interrupt-on-change. The DEFVAL and INTCON
registers must also be configured if any pins are
enabled for interrupt-on-change.
1.6.4DEFAULT COMPARE REGISTER
FOR INTERRUPT-ON-CHANGE
The default comparison value is configured in the
DEFVAL register. If enabled (via GPINTEN and
INTCON) to compare against the DEFVAL register, an
opposite value on the associated pin will cause an
interrupt to occur.
REGISTER 1-4:DEFVAL – DEFAULT VALUE REGISTER (ADDR 0x03)