PU2CLR MCP23008 Arduino Library  1.0.7
Arduino Library for MCP23008 Device - By Ricardo Lima Caratti
MCP23008 IO functions

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...
 

Detailed Description

Function Documentation

◆ getGPIOS()

uint8_t MCP::getGPIOS ( )
inline

Returns the current MCP GPIO pin levels.

Returns
uint8_t

◆ setGPIOS()

void MCP::setGPIOS ( uint8_t  value)
inline

Sets a value to the GPIO Register.

A direct way to set a given value to deal with the GPIOs pins.

Parameters
value(8 bits)

◆ getINTCAP()

uint8_t MCP::getINTCAP ( )
inline

Returns the last value of INTCAP register (value immediately after the last interrupt event)

Returns
uint8_t

◆ getINTF()

uint8_t MCP::getINTF ( )
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.

Returns
uint8_t

◆ getRegister()

uint8_t MCP::getRegister ( uint8_t  reg)

Gets the corrent register information.

Gets the current register content.

Parameters
reg(0x00 ~ 0xA) see MCP23008 registers documentation
Returns
uint8_t current register value

◆ setRegister()

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.

Parameters
reg(0x00 ~ 0xA) see MCP23008 registers documentation
valuevalue (8 bits)

◆ turnGpioOn()

void MCP::turnGpioOn ( uint8_t  gpio)

Turns a given GPIO port on (high level)

Sets a given GPIO pin high

Parameters
gpiothe GPIO/PIN number (0-7)

◆ turnGpioOff()

void MCP::turnGpioOff ( uint8_t  gpio)

Turns a given GPIO port off (low level)

Sets a given GPIO pin to low

Parameters
gpiothe GPIO/PIN number (0-7)

◆ gpioRead()

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.

Parameters
gpiopin number
Returns
true if it is High

◆ gpioWrite()

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()

Parameters
gpiopin number
value1 = High; 0 = Low

◆ registerDigitalRead()

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.

Parameters
bit_positionbit position
Returns
true if it is High

◆ registerDigitalWrite()

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

Parameters
mcp_registerMCM23008 register
bit_positionbit position
value0 = Low; 1 = High

◆ pullUpGpioOn()

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

Parameters
gpiothe GPIO/PIN number (0-7)

◆ pullUpGpioOff()

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

Parameters
gpiothe GPIO/PIN number (0-7)

◆ setIoCon()

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.

Parameters
INTPOLThis bit sets the polarity of the INT output pin. 1= Active-high. 0 = Active - low.
ODRThis bit configures the INT pin as an open-drain output. 1 = Open-drain. 0 = Active driver.
HAENHardware Address Enable bit (MCP23S08 only). 1 = Enables.
DISSLWSlew Rate control bit for SDA output. 1= Slewratedisabled. 0= Slewrateenabled.
SEQOPSequential Operation mode bit. 1 = Sequential operation disabled, address pointer does not increment.

◆ getIoCon()

mcp23008_ioncon MCP::getIoCon ( )

Returns the IOCON content.

This function returns a mcp23008_ioncon datatype with the IOCON register content

See also
mcp23008_ioncon
Returns
mcp23008_ioncon content

◆ invertGpioPolarity()

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.

See also
setRegister

◆ setInterrupt()

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.

Parameters
polatitysets the polarity of the INT output pin. 1 = Active-high; 0 = Active-low.
openDrainOutputconfigures 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).

◆ interruptGpioOn()

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.

Parameters
gpioGPIO / PIN you want to configure
bitCompareThe default comparison bit value that should be configured in the DEFVAL register.