Erriez MCP23017 library for Arduino  1.0.0
This is a MCP23017 16-pin I2C IO-Expander library for Arduino by Erriez.
Classes | Macros
ErriezMCP23017.h File Reference

MCP23017 I2C IO expander library for Arduino. More...

#include <Arduino.h>
#include <Wire.h>
Include dependency graph for ErriezMCP23017.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ErriezMCP23017
 Erriez MCP23017 I2C IO-Expander class. More...
 

Macros

#define MCP23017_I2C_ADDRESS   0x20
 Default MCP23017 I2C address.
 
#define MCP23017_REG_IODIR   0x00
 Controls the direction of the data I/O for port A.
 
#define MCP23017_REG_IPOL   0x02
 Configures the polarity on the corresponding GPIO port bits for port A.
 
#define MCP23017_REG_GPINTEN   0x04
 Controls the interrupt-on-change for each pin of port A.
 
#define MCP23017_REG_DEFVAL   0x06
 Controls the default comparaison value for interrupt-on-change for port A.
 
#define MCP23017_REG_INTCON   0x08
 Controls how the associated pin value is compared for the interrupt-on-change for port A.
 
#define MCP23017_REG_IOCON   0x0A
 Configuration register A.
 
#define MCP23017_REG_GPPU   0x0C
 Controls the pull-up resistors for the port A pins.
 
#define MCP23017_REG_INTF   0x0E
 Reflects the interrupt condition on the port A pins.
 
#define MCP23017_REG_INTCAP   0x10
 Captures the port A value at the time the interrupt occured.
 
#define MCP23017_REG_GPIO   0x12
 Reflects the value on the port A.
 
#define MCP23017_REG_OLAT   0x14
 Provides access to the port A output latches.
 
#define MCP23017_NUM_REGS   0x16
 Total number of registers.
 
#define MCP23017_NUM_PINS   16
 Total number of pins port A + B.
 
#define MCP23017_MASK_ALL_PINS   0xFFFF
 All 16-pins mask.
 
#define MCP23017_MASK_REG_A   0x1E
 Address mask to select A registers on even addresses.
 
#define IOCON_BANK   7
 Controls how the registers are addressed.
 
#define IOCON_MIRROR   6
 INT Pins Mirror bit.
 
#define IOCON_SEQOP   5
 Sequential Operation mode bit.
 
#define IOCON_DISSLW   4
 Slew Rate control bit for SDA output.
 
#define IOCON_ODR   2
 Configures the INT pin as an open-drain output.
 
#define IOCON_INTPOL   1
 This bit sets the polarity of the INT output pin.
 
#define REG_IOCON_VALUE
 Default MCP23017 configuration. More...
 

Detailed Description

MCP23017 I2C IO expander library for Arduino.

Source: https://github.com/Erriez/ErriezMCP23017 Documentation: https://erriez.github.io/ErriezMCP23017


Design notes:

1 This library is designed for MCP23017 with I2C interface.

2 This library does not support the MCP23S017 with SPI interface. Workaround: None, use another library, or add SPI support to this library.

3 The INTB is not enabled in this library, because. INTA and INTB interrupts are ORed to INTA with configuration bit MIRROR=1 in IOCON register. Workaround: The application shall only use INTA.

4 Port, direction and pull-up states are cached in variables for speed: No additional register reads are needed.


MCP23017 limitations:

1 The MCP23017 does not support rising or falling edge interrupts. Workaround: None: The MCP23017 support only the following interrupts:

2 Note: The register IODIR bits are reversed: 0: Output 1: Input Workaround: Be careful with interpreting register IODIR.


MCP23017 major bugs:

1 The INTA pin is released when reading from register GPIO or INTCAP. This happens when the application calls function pinRead() or portRead(). This is a documented chip limitation. Workaround: None.

2 Register INTF captures only one pin change. The MCP23017 does not update register INTF when multiple interrupts occurs at the same time. Workaround:

  1. The application shall read the INTF register with function getPortIntertuptStatus() as fast as possible after INTA is asserted. otherwise multiple pin interrupts are lost.
  2. The application shall poll pin INTA and read GPIO pin manually to detect pin changes.

Definition in file ErriezMCP23017.h.

Macro Definition Documentation

◆ REG_IOCON_VALUE

#define REG_IOCON_VALUE
Value:
((0<<IOCON_BANK) | /* 1 = The registers associated with each port are separated into different banks. */ \
(1<<IOCON_MIRROR) | /* 1 = INTA and INTB pins are OR'ed to INTA (INTB disabled) */ \
(0<<IOCON_SEQOP) | /* 1 = Sequential operation disabled, address pointer does not increment. */ \
(0<<IOCON_DISSLW) | /* 1 = Slew rate disabled */ \
(0<<IOCON_ODR) | /* 1 = Open-drain output (overrides the INTPOL bit.) */ \
(0<<IOCON_INTPOL)) /* 1 = Active-high */
#define IOCON_DISSLW
Slew Rate control bit for SDA output.
#define IOCON_BANK
Controls how the registers are addressed.
#define IOCON_SEQOP
Sequential Operation mode bit.
#define IOCON_ODR
Configures the INT pin as an open-drain output.
#define IOCON_MIRROR
INT Pins Mirror bit.
#define IOCON_INTPOL
This bit sets the polarity of the INT output pin.

Default MCP23017 configuration.

Definition at line 124 of file ErriezMCP23017.h.