39 _wire(twoWire), _i2cAddress(i2cAddress), _i2cStatus(0),
40 _gpioPort(0), _gpioDir(0), _gpioPullup(0)
62 if (_i2cStatus != 0) {
102 _gpioDir |= (1<<pin);
106 _gpioPullup &= ~(1<<pin);
108 _gpioDir &= ~(1<<pin);
112 _gpioPullup |= (1<<pin);
114 _gpioDir &= ~(1<<pin);
162 _gpioDir = outputPins;
191 _gpioPullup = pullupPins;
295 _gpioPort &= ~(maskClear);
296 _gpioPort |= maskSet;
418 if ((_portStateLast & pinsChanged) == (pinsChanged &
portState)) {
443 _wire->beginTransmission(_i2cAddress);
445 _i2cStatus = _wire->endTransmission(
false);
448 (void)_wire->requestFrom(_i2cAddress, (uint8_t)2);
451 return _wire->read() | (_wire->read() << 8);
464 _wire->beginTransmission(_i2cAddress);
466 _wire->write(value & 0xff);
467 _wire->write(value >> 8);
469 _i2cStatus = _wire->endTransmission(
true);
496 serial->println(F(
"MCP23017 registers:"));
498 serial->print(F(
" 00 IODIR: 0x"));
500 serial->print(F(
" 02 IPOL: 0x"));
502 serial->print(F(
" 04 GPINTEN: 0x"));
504 serial->print(F(
" 06 DEFVAL: 0x"));
506 serial->print(F(
" 08 INTCON: 0x"));
508 serial->print(F(
" 0A IOCON: 0x"));
510 serial->print(F(
" 0C GPPU: 0x"));
512 serial->print(F(
" 0E INTF: 0x"));
514 serial->print(F(
" 10 INTCAP: 0x"));
516 serial->print(F(
" 12 GPIO: 0x"));
518 serial->print(F(
" 14 OLAT: 0x"));
bool pinRead(uint8_t pin)
Read state of a single pin (input and output pins)
#define MCP23017_REG_INTCON
Controls how the associated pin value is compared for the interrupt-on-change for port A...
#define MCP23017_REG_IODIR
Controls the direction of the data I/O for port A.
void digitalWrite(uint8_t pin, uint8_t level)
Set state of a single pin.
void portMask(uint16_t maskSet, uint16_t maskClear)
Clear and set pin states.
void setPortDirection(uint16_t outputPins)
Set PORT direction all pins.
#define MCP23017_REG_GPINTEN
Controls the interrupt-on-change for each pin of port A.
void pinMode(uint8_t pin, uint8_t mode)
Set direction of a single pin.
#define MCP23017_REG_GPPU
Controls the pull-up resistors for the port A pins.
uint16_t portState
Port state since last portRead() call.
#define MCP23017_REG_OLAT
Provides access to the port A output latches.
#define MCP23017_REG_INTCAP
Captures the port A value at the time the interrupt occured.
uint16_t pinsChanged
Pins change on interrupt enabled pins since last intPinChanged() call.
void pinToggle(uint8_t pin)
Toggle state of a single pin (only for output pins)
#define MCP23017_REG_GPIO
Reflects the value on the port A.
void dumpRegisters(HardwareSerial *serial)
Print I2C registers on serial port.
uint16_t getPortInterruptMask()
Get interrupt mask all pins.
void setInterruptPolarityINTA(bool activeHigh)
Set interrupt polarity INTA.
void registerWrite(uint8_t reg, uint16_t value)
MCP23017 I2C write register.
void portWrite(uint16_t value)
Set all pin states.
MCP23017 I2C IO expander library for Arduino.
#define MCP23017_REG_IOCON
Configuration register A.
#define REG_IOCON_VALUE
Default MCP23017 configuration.
#define MCP23017_REG_DEFVAL
Controls the default comparaison value for interrupt-on-change for port A.
uint16_t portRead()
Read PORT of all pins (input and output pins)
void setPortPullup(uint16_t pullupPins)
Set PORT pullup all pins.
uint16_t pinsFalling
Falling edge on interrupt enabled pins since last intPinChanged() call.
void pinWrite(uint8_t pin, bool level)
Set pin state.
#define MCP23017_NUM_PINS
Total number of pins port A + B.
bool begin(bool reset=true)
Initialize MCP23017.
uint16_t pinsRising
Rising edge on interrupt eanbled pins since last intPinChanged() call.
uint16_t getPortPullup()
Get PORT pullup all pins.
uint16_t registerRead(uint8_t reg)
MCP23017 I2C read register.
bool interruptINTA()
MCP23017 INTA pin changed.
void setPortInterruptDisable(uint16_t pins)
Disable interrupt on pins.
void setPortInterruptEnable(uint16_t pins)
Enable interrupt change on pins.
void portToggle(uint16_t value)
Toggle pin states (output pins only)
uint8_t getI2CStatus()
Return status of the last I2C write, returned by Wire endTransfer()
int digitalRead(uint8_t pin)
Get state of a single pin.
#define MCP23017_MASK_ALL_PINS
All 16-pins mask.
ErriezMCP23017(uint8_t i2cAddress=MCP23017_I2C_ADDRESS, TwoWire *twoWire=&Wire)
ErriezMCP23017 Constructor.
uint16_t getPortDirection()
Get PORT direction all pins.
#define MCP23017_REG_IPOL
Configures the polarity on the corresponding GPIO port bits for port A.
#define MCP23017_REG_INTF
Reflects the interrupt condition on the port A pins.
#define MCP23017_MASK_REG_A
Address mask to select A registers on even addresses.
#define IOCON_INTPOL
This bit sets the polarity of the INT output pin.