Daniel Wyatt / MCP23008
Embed: (wiki syntax)

« Back to documentation index

MCP23008 Class Reference

MCP23008 Class Reference

MCP23008 class. More...

#include <MCP23008.hpp>

Public Member Functions

 MCP23008 (PinName sda, PinName scl, uint8_t address, Frequency freq=Frequency_100KHz)
 Constructor.
void set_input_pins (uint8_t pins)
 Set pins to input mode.
void set_output_pins (uint8_t pins)
 Set pins to output mode.
void write_outputs (uint8_t values)
 Write to the output pins.
uint8_t read_outputs ()
 Read back the outputs.
uint8_t read_inputs ()
 Read from the input pins.
void set_input_polarity (uint8_t values)
 Set the input pin polarity.
uint8_t get_input_polarity ()
 Read back the current input pin polarity.
void set_pullups (uint8_t values)
 Enable and disable the internal pull-up resistors for input pins.
uint8_t get_pullups ()
 Get the current state of the internal pull-up resistors.
void interrupt_on_changes (uint8_t pins)
 Generate an interrupt when a pin changes.
void disable_interrupts (uint8_t pins)
 Disables interrupts for the specified pins.
void acknowledge_interrupt (uint8_t &pin, uint8_t &values)
 Acknowledge a generated interrupt.

Detailed Description

MCP23008 class.

Allow access to an I2C connected MCP23008 8-bit I/O extender chip

Definition at line 8 of file MCP23008.hpp.


Constructor & Destructor Documentation

MCP23008 ( PinName  sda,
PinName  scl,
uint8_t  address,
Frequency  freq = Frequency_100KHz 
)

Constructor.

Parameters:
sdaI2C sda pin
sclI2C scl pin
addressThe hardware address of the MCP23008. This is the 3-bit value that is physically set via A0, A1, and A2.
freqThe I2C frequency. Should probably be 100KHz or 400KHz.

Definition at line 20 of file MCP23008.cpp.


Member Function Documentation

void acknowledge_interrupt ( uint8_t &  pin,
uint8_t &  values 
)

Acknowledge a generated interrupt.

This function must be called when an interrupt is generated to discover which pin caused the interrupt and to enable future interrupts.

Parameters:
pinAn output paramter that specifies which pin generated the interrupt.
valuesThe current state of the input pins.

Definition at line 83 of file MCP23008.cpp.

void disable_interrupts ( uint8_t  pins )

Disables interrupts for the specified pins.

Parameters:
valuesA bitmask indicating which interrupts should be disabled.

Definition at line 77 of file MCP23008.cpp.

uint8_t get_input_polarity (  )

Read back the current input pin polarity.

This function reads the current state of the input pin polarity.

Returns:
The value from the IPOL register.

Definition at line 56 of file MCP23008.cpp.

uint8_t get_pullups (  )

Get the current state of the internal pull-up resistors.

Returns:
The current state of the pull-up resistors.

Definition at line 64 of file MCP23008.cpp.

void interrupt_on_changes ( uint8_t  pins )

Generate an interrupt when a pin changes.

This function enables interrupt generation for the specified pins. The interrupt is active-low by default. The function acknowledge_interrupt must be called before another interrupt will be generated. Example:

 InterruptIn in ( p16 );
 MCP23008 mcp ( p9, p10, 0 );
 in.fall ( &interrupt );
 mcp.interrupt_on_changes ( MCP23008::Pin_GP0 );
 while ( 1 ) {
      wait ( 1 );
 }
Parameters:
pinsA bitmask of the pins that may generate an interrupt.

Definition at line 68 of file MCP23008.cpp.

uint8_t read_inputs (  )

Read from the input pins.

This function is used to read the values from the input pins.

Returns:
A bitmask of the current state of the input pins.

Definition at line 48 of file MCP23008.cpp.

uint8_t read_outputs (  )

Read back the outputs.

This function is used to read the last values written to the output pins.

Returns:
The value from the OLAT register.

Definition at line 44 of file MCP23008.cpp.

void set_input_pins ( uint8_t  pins )

Set pins to input mode.

This function is used to set which pins are inputs (if any). Example: set_inputs ( Pin_GP0 | Pin_GP1 | Pin_GP2 ); Note that these are set to input in addition to the previously set. In other words, the following: set_inputs ( Pin_GP1 ); set_inputs ( Pin_GP2 ); Results in at least two pins set to input.

Parameters:
pinsA bitmask of pins to set to input mode.

Definition at line 30 of file MCP23008.cpp.

void set_input_polarity ( uint8_t  values )

Set the input pin polarity.

This function sets the polarity of the input pins. A 1 bit is inverted polarity, a 0 is normal.

Parameters:
valuesA bitmask of the input polarity.

Definition at line 52 of file MCP23008.cpp.

void set_output_pins ( uint8_t  pins )

Set pins to output mode.

This function is used to set which pins are outputs (if any). Example: set_outputs ( Pin_GP0 | Pin_GP1 | Pin_GP2 ); Note that these are set to output in addition to the previously set. In other words, the following: set_outputs ( Pin_GP1 ); set_outputs ( Pin_GP2 ); Results in at least two pins set to output.

Parameters:
pinsA bitmask of pins to set to output mode.

Definition at line 35 of file MCP23008.cpp.

void set_pullups ( uint8_t  values )

Enable and disable the internal pull-up resistors for input pins.

This function enables the internal 100 kΩ pull-up resistors. A 1 bit enables the pull-up resistor for the corresponding input pin.

Parameters:
valuesA bitmask indicating which pull-up resistors should be enabled/disabled.

Definition at line 60 of file MCP23008.cpp.

void write_outputs ( uint8_t  values )

Write to the output pins.

This function is used to set output pins on or off.

Parameters:
valuesA bitmask indicating whether a pin should be on or off.

Definition at line 40 of file MCP23008.cpp.