![]() |
Erriez MCP23017 library for Arduino
1.0.0
This is a MCP23017 16-pin I2C IO-Expander library for Arduino by Erriez.
|
Erriez MCP23017 I2C IO-Expander class. More...
#include <ErriezMCP23017.h>
Public Member Functions | |
ErriezMCP23017 (uint8_t i2cAddress=MCP23017_I2C_ADDRESS, TwoWire *twoWire=&Wire) | |
ErriezMCP23017 Constructor. More... | |
bool | begin (bool reset=true) |
Initialize MCP23017. More... | |
void | pinMode (uint8_t pin, uint8_t mode) |
Set direction of a single pin. More... | |
void | digitalWrite (uint8_t pin, uint8_t level) |
Set state of a single pin. More... | |
int | digitalRead (uint8_t pin) |
Get state of a single pin. More... | |
void | setPortDirection (uint16_t outputPins) |
Set PORT direction all pins. More... | |
uint16_t | getPortDirection () |
Get PORT direction all pins. More... | |
void | setPortPullup (uint16_t pullupPins) |
Set PORT pullup all pins. More... | |
uint16_t | getPortPullup () |
Get PORT pullup all pins. More... | |
void | pinWrite (uint8_t pin, bool level) |
Set pin state. More... | |
void | pinToggle (uint8_t pin) |
Toggle state of a single pin (only for output pins) More... | |
bool | pinRead (uint8_t pin) |
Read state of a single pin (input and output pins) More... | |
void | portWrite (uint16_t value) |
Set all pin states. More... | |
void | portToggle (uint16_t value) |
Toggle pin states (output pins only) More... | |
void | portMask (uint16_t maskSet, uint16_t maskClear) |
Clear and set pin states. More... | |
uint16_t | portRead () |
Read PORT of all pins (input and output pins) More... | |
void | setInterruptPolarityINTA (bool activeHigh) |
Set interrupt polarity INTA. More... | |
uint16_t | getPortInterruptMask () |
Get interrupt mask all pins. More... | |
void | setPortInterruptEnable (uint16_t pins) |
Enable interrupt change on pins. More... | |
void | setPortInterruptDisable (uint16_t pins) |
Disable interrupt on pins. More... | |
bool | interruptINTA () |
MCP23017 INTA pin changed. More... | |
uint16_t | registerRead (uint8_t reg) |
MCP23017 I2C read register. More... | |
void | registerWrite (uint8_t reg, uint16_t value) |
MCP23017 I2C write register. More... | |
uint8_t | getI2CStatus () |
Return status of the last I2C write, returned by Wire endTransfer() More... | |
void | dumpRegisters (HardwareSerial *serial) |
Print I2C registers on serial port. More... | |
Public Attributes | |
uint16_t | portState |
Port state since last portRead() call. | |
uint16_t | pinsChanged |
Pins change on interrupt enabled pins since last intPinChanged() call. | |
uint16_t | pinsFalling |
Falling edge on interrupt enabled pins since last intPinChanged() call. | |
uint16_t | pinsRising |
Rising edge on interrupt eanbled pins since last intPinChanged() call. | |
Erriez MCP23017 I2C IO-Expander class.
Definition at line 135 of file ErriezMCP23017.h.
ErriezMCP23017::ErriezMCP23017 | ( | uint8_t | i2cAddress = MCP23017_I2C_ADDRESS , |
TwoWire * | twoWire = &Wire |
||
) |
ErriezMCP23017 Constructor.
The constructor initializes internal variables and does not call I2C functions
i2cAddress | 7-bit MCP23017 I2C device address |
twoWire | Default is Wire object to select I2C bus. |
Definition at line 38 of file ErriezMCP23017.cpp.
bool ErriezMCP23017::begin | ( | bool | reset = true | ) |
Initialize MCP23017.
reset | Perform resetting registers to default values (Default enabled) |
true | MCP23017 detected |
false | MCP23017 not detected |
Definition at line 55 of file ErriezMCP23017.cpp.
int ErriezMCP23017::digitalRead | ( | uint8_t | pin | ) |
Get state of a single pin.
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
HIGH | = 1 |
LOW | = 0 |
Definition at line 145 of file ErriezMCP23017.cpp.
void ErriezMCP23017::digitalWrite | ( | uint8_t | pin, |
uint8_t | state | ||
) |
Set state of a single pin.
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
state | HIGH = 1 LOW = 0 |
Definition at line 132 of file ErriezMCP23017.cpp.
void ErriezMCP23017::dumpRegisters | ( | HardwareSerial * | serial | ) |
Print I2C registers on serial port.
This function is optimized away by the compiler when not used
serial | Serial port |
Definition at line 494 of file ErriezMCP23017.cpp.
uint8_t ErriezMCP23017::getI2CStatus | ( | ) |
Return status of the last I2C write, returned by Wire endTransfer()
0 | Success |
1 | Data too long to fit in transmit buffer |
2 | Received NACK on transmit of address |
3 | Received NACK on transmit of data |
4 | Other error |
Definition at line 480 of file ErriezMCP23017.cpp.
uint16_t ErriezMCP23017::getPortDirection | ( | ) |
Get PORT direction all pins.
Definition at line 174 of file ErriezMCP23017.cpp.
uint16_t ErriezMCP23017::getPortInterruptMask | ( | ) |
Get interrupt mask all pins.
Definition at line 345 of file ErriezMCP23017.cpp.
uint16_t ErriezMCP23017::getPortPullup | ( | ) |
Get PORT pullup all pins.
Definition at line 203 of file ErriezMCP23017.cpp.
bool ErriezMCP23017::interruptINTA | ( | ) |
MCP23017 INTA pin changed.
The application should call this function when the MCP23017 INTA pin changed. Default: Falling edge This function re
true | At least one pin changed |
false | No pins changed (Pin pulse was too short, or INTA edge did not match) |
Definition at line 401 of file ErriezMCP23017.cpp.
void ErriezMCP23017::pinMode | ( | uint8_t | pin, |
uint8_t | mode | ||
) |
Set direction of a single pin.
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
mode | OUTPUT: Configure pin as output INPUT: Configure pin as input INPUT_PULLUP: Configure pin with input pull-up |
Definition at line 95 of file ErriezMCP23017.cpp.
bool ErriezMCP23017::pinRead | ( | uint8_t | pin | ) |
Read state of a single pin (input and output pins)
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
HIGH | = 1 |
LOW | = 0 |
Definition at line 248 of file ErriezMCP23017.cpp.
void ErriezMCP23017::pinToggle | ( | uint8_t | pin | ) |
Toggle state of a single pin (only for output pins)
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
Definition at line 233 of file ErriezMCP23017.cpp.
void ErriezMCP23017::pinWrite | ( | uint8_t | pin, |
bool | level | ||
) |
Set pin state.
pin | Pin number 0..15 (PORTA = 0..7, PORTB = 8..15) |
level | HIGH = 1, LOW = 0 |
Definition at line 217 of file ErriezMCP23017.cpp.
void ErriezMCP23017::portMask | ( | uint16_t | maskSet, |
uint16_t | maskClear | ||
) |
Clear and set pin states.
maskSet | Bit value '1': Pins to HIGH |
maskClear | Bit value '1': Pins to LOW |
Definition at line 293 of file ErriezMCP23017.cpp.
uint16_t ErriezMCP23017::portRead | ( | ) |
Read PORT of all pins (input and output pins)
Definition at line 305 of file ErriezMCP23017.cpp.
void ErriezMCP23017::portToggle | ( | uint16_t | value | ) |
Toggle pin states (output pins only)
value | 16 pins, bit value '0' = unchanged, '1' = toggle |
Definition at line 278 of file ErriezMCP23017.cpp.
void ErriezMCP23017::portWrite | ( | uint16_t | value | ) |
Set all pin states.
value | 16 pins, bit value '0' = LOW, '1' = HIGH |
Definition at line 265 of file ErriezMCP23017.cpp.
uint16_t ErriezMCP23017::registerRead | ( | uint8_t | reg | ) |
MCP23017 I2C read register.
reg | MCP23017 register |
Definition at line 441 of file ErriezMCP23017.cpp.
void ErriezMCP23017::registerWrite | ( | uint8_t | reg, |
uint16_t | value | ||
) |
MCP23017 I2C write register.
reg | MCP23017 register |
value | MCP23017 value |
Definition at line 461 of file ErriezMCP23017.cpp.
void ErriezMCP23017::setInterruptPolarityINTA | ( | bool | activeHigh | ) |
Set interrupt polarity INTA.
activeHigh | HIGH = 1: Active high, LOW = 0: Active low (default) |
Definition at line 320 of file ErriezMCP23017.cpp.
void ErriezMCP23017::setPortDirection | ( | uint16_t | outputPins | ) |
Set PORT direction all pins.
outputPins | PORT direction pins 0..15, Arduino compatible: Bit value '0': INPUT Bit value '1': OUTPUT |
Definition at line 159 of file ErriezMCP23017.cpp.
void ErriezMCP23017::setPortInterruptDisable | ( | uint16_t | pins | ) |
Disable interrupt on pins.
pins | Pins to disable |
Definition at line 375 of file ErriezMCP23017.cpp.
void ErriezMCP23017::setPortInterruptEnable | ( | uint16_t | pins | ) |
Enable interrupt change on pins.
The MCP23017 does not support edge interrupts. This is handled by software.
pins | Pins to enable interrupt change |
Definition at line 357 of file ErriezMCP23017.cpp.
void ErriezMCP23017::setPortPullup | ( | uint16_t | pullupPins | ) |
Set PORT pullup all pins.
pullupPins | Set PORT pull-up pins 0..15: Bit value '0': Pull-up unchanged Bit value '1': Pull-up enable |
Definition at line 188 of file ErriezMCP23017.cpp.