PU2CLR MCP23008 Arduino Library
1.0.7
Arduino Library for MCP23008 Device - By Ricardo Lima Caratti
|
Functions | |
uint8_t | MCP::getGPIOS () |
Returns the current MCP GPIO pin levels. More... | |
void | MCP::setGPIOS (uint8_t value) |
Sets a value to the GPIO Register. More... | |
uint8_t | MCP::getINTCAP () |
Returns the last value of INTCAP register (value immediately after the last interrupt event) More... | |
uint8_t | MCP::getINTF () |
Returns the last value of INTF register. More... | |
uint8_t | MCP::getRegister (uint8_t reg) |
Gets the corrent register information. More... | |
void | MCP::setRegister (uint8_t reg, uint8_t value) |
Sets a value to a given register. More... | |
void | MCP::turnGpioOn (uint8_t gpio) |
Turns a given GPIO port on (high level) More... | |
void | MCP::turnGpioOff (uint8_t gpio) |
Turns a given GPIO port off (low level) More... | |
bool | MCP::gpioRead (uint8_t gpio) |
Reads the status (high or low) of a given GPIO. More... | |
void | MCP::gpioWrite (uint8_t gpio, uint8_t value) |
Sets a given value (high(1) or low(0) ) to a given gpio pin. More... | |
bool | MCP::registerDigitalRead (uint8_t mcp_register, uint8_t bit_position) |
Reads the status (high or low) of a given bit (position) of a given MCP23008 register. More... | |
void | MCP::registerDigitalWrite (uint8_t mcp_register, uint8_t bit_position, uint8_t value) |
Sets High or Low to a given position in a given MCP23008 register. More... | |
void | MCP::pullUpGpioOn (uint8_t gpio) |
Turns intenal pull up resistor ON to a given GPIO PIN (high level) More... | |
void | MCP::pullUpGpioOff (uint8_t gpio) |
Turns intenal pull up resistor OFF to a given GPIO PIN (low level) More... | |
void | MCP::setIoCon (uint8_t INTPOL, uint8_t ODR, uint8_t HAEN, uint8_t DISSLW, uint8_t SEQOP) |
Sets the IO Configurarion gerister. More... | |
mcp23008_ioncon | MCP::getIoCon () |
Returns the IOCON content. More... | |
void | MCP::invertGpioPolarity () |
Inverts the polarity of the all GPIO port bits. More... | |
void | MCP::setInterrupt (uint8_t polatity=0, uint8_t openDrainOutput=0) |
Configures the MCP23008 interrupt feature. More... | |
void | MCP::interruptGpioOn (uint8_t gpio, uint8_t bitCompare=1) |
Sets the interrupt-on-change feature to a given GPIO pin. More... | |
|
inline |
Returns the current MCP GPIO pin levels.
|
inline |
Sets a value to the GPIO Register.
A direct way to set a given value to deal with the GPIOs pins.
value | (8 bits) |
|
inline |
Returns the last value of INTCAP register (value immediately after the last interrupt event)
|
inline |
Returns the last value of INTF register.
The INTF register reflects the interrupt condition on the port pins of any pin that is enabled for interrupts via the GPINTEN register. A ‘set’ bit indicates that the associated pin caused the interrupt.
uint8_t MCP::getRegister | ( | uint8_t | reg | ) |
Gets the corrent register information.
Gets the current register content.
reg | (0x00 ~ 0xA) see MCP23008 registers documentation |
void MCP::setRegister | ( | uint8_t | reg, |
uint8_t | value | ||
) |
Sets a value to a given register.
Sets a given 8 bit value to a given register.
reg | (0x00 ~ 0xA) see MCP23008 registers documentation |
value | value (8 bits) |
void MCP::turnGpioOn | ( | uint8_t | gpio | ) |
Turns a given GPIO port on (high level)
Sets a given GPIO pin high
gpio | the GPIO/PIN number (0-7) |
void MCP::turnGpioOff | ( | uint8_t | gpio | ) |
Turns a given GPIO port off (low level)
Sets a given GPIO pin to low
gpio | the GPIO/PIN number (0-7) |
bool MCP::gpioRead | ( | uint8_t | gpio | ) |
Reads the status (high or low) of a given GPIO.
Returns true if the gpio is hight or fale if it is low.
gpio | pin number |
void MCP::gpioWrite | ( | uint8_t | gpio, |
uint8_t | value | ||
) |
Sets a given value (high(1) or low(0) ) to a given gpio pin.
It is like the turnGpioOn()
gpio | pin number |
value | 1 = High; 0 = Low |
bool MCP::registerDigitalRead | ( | uint8_t | mcp_register, |
uint8_t | bit_position | ||
) |
Reads the status (high or low) of a given bit (position) of a given MCP23008 register.
Returns true if the bit of the register is hight or fale if it is low.
bit_position | bit position |
void MCP::registerDigitalWrite | ( | uint8_t | mcp_register, |
uint8_t | bit_position, | ||
uint8_t | value | ||
) |
Sets High or Low to a given position in a given MCP23008 register.
Sets a given bit value to a given position in a given MCP23008 register
mcp_register | MCM23008 register |
bit_position | bit position |
value | 0 = Low; 1 = High |
void MCP::pullUpGpioOn | ( | uint8_t | gpio | ) |
Turns intenal pull up resistor ON to a given GPIO PIN (high level)
Activates the pull up resistor to a given GPIO pin
gpio | the GPIO/PIN number (0-7) |
void MCP::pullUpGpioOff | ( | uint8_t | gpio | ) |
Turns intenal pull up resistor OFF to a given GPIO PIN (low level)
Deactivates the pull up resistor to a given GPIO pin
gpio | the GPIO/PIN number (0-7) |
void MCP::setIoCon | ( | uint8_t | INTPOL, |
uint8_t | ODR, | ||
uint8_t | HAEN, | ||
uint8_t | DISSLW, | ||
uint8_t | SEQOP | ||
) |
Sets the IO Configurarion gerister.
The IOCON register contains several bits for configuring the device:
TheSequentialOperation(SEQOP)controlsthe incrementing function of the address pointer.
If the address pointer is disabled, the address pointer does not automatically increment after each byte is clocked during a serial transfer.
This feature is useful when it is desired to continuously poll (read) or modify (write) a register.
TheSlewRate(DISSLW)bitcontrolstheslew rate function on the SDA pin. If enabled, the SDA slew rate will be controlled when driving from a high to a low.
TheHardwareAddressEnable(HAEN)controlbit enables/disables the hardware address pins (A1, A0) on the MCP23S08. This bit is not used on the MCP23008. The address pins are always enabled on the MCP23008.
TheOpen-Drain(ODR)controlbitenables/ disables the INT pin for open-drain configuration.
TheInterruptPolarity(INTPOL)controlbitsets the polarity of the INT pin. This bit is functional only when the ODR bit is cleared, configuring the INT pin as active push-pull.
INTPOL | This bit sets the polarity of the INT output pin. 1= Active-high. 0 = Active - low. |
ODR | This bit configures the INT pin as an open-drain output. 1 = Open-drain. 0 = Active driver. |
HAEN | Hardware Address Enable bit (MCP23S08 only). 1 = Enables. |
DISSLW | Slew Rate control bit for SDA output. 1= Slewratedisabled. 0= Slewrateenabled. |
SEQOP | Sequential Operation mode bit. 1 = Sequential operation disabled, address pointer does not increment. |
mcp23008_ioncon MCP::getIoCon | ( | ) |
Returns the IOCON content.
This function returns a mcp23008_ioncon datatype with the IOCON register content
void MCP::invertGpioPolarity | ( | ) |
Inverts the polarity of the all GPIO port bits.
The IPOL 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.
Use the primitive setRegister(REG_IPOL, reg_value) if you ant to invert only a specific gpio.
void MCP::setInterrupt | ( | uint8_t | polatity = 0 , |
uint8_t | openDrainOutput = 0 |
||
) |
Configures the MCP23008 interrupt feature.
The INT output pin will be activated when an internal interrupt occurs.
The interrupt block can be configured by the following registers: GPINTEN, DEFVAL, INTCON and IOCON(ODRandINPOL).
This method work on IOCON.
polatity | sets the polarity of the INT output pin. 1 = Active-high; 0 = Active-low. |
openDrainOutput | configures the INT pin as an open-drain output. 1 = Open-drain output (overrides the INTPOL bit). 0 = Active driver output (INTPOL bit sets the polarity). |
void MCP::interruptGpioOn | ( | uint8_t | gpio, |
uint8_t | bitCompare = 1 |
||
) |
Sets the interrupt-on-change feature to a given GPIO pin.
The GPINTEN register controls the interrupt-on-change 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.
if you want to configure more than one GPIO at once, use the primitive setRegister(REG_GPINTEN, reg);
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.
gpio | GPIO / PIN you want to configure |
bitCompare | The default comparison bit value that should be configured in the DEFVAL register. |