Knud Dalgaard / 310-TMC3-TestHW

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

MCP23008 Class Reference

MCP23008 Class Reference

MCP23008 class. More...

#include <MCP23008.h>

Public Member Functions

 MCP23008 (PinName sda, PinName scl, int i2cAddress)
 Constructor for the MCP23008 connected to specified I2C pins at a specific address.
void reset (void)
 Reset MCP23008 device to its power-on state.
void config (unsigned char dir_config, unsigned char pullup_config, unsigned char polarity_config)
 Configure an MCP23008 device.
void write_mask (unsigned char data, unsigned char mask)
 Write a masked 16-bit value to the device.
int read_mask (unsigned char mask)
 Read a 8-bit value from the device and apply mask.
void write_bit (int value, int bit_number)
 Write a 0/1 value to an output bit.
int read_bit (int bit_number)
 Read a 0/1 value from an input bit.

Detailed Description

MCP23008 class.

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

      MCP23008     *par_port; 
        ...
        par_port = new MCP23008( p9, p10, I2C_ADD);
        par_port->config(0xF0,0,0); 

Definition at line 68 of file MCP23008.h.


Constructor & Destructor Documentation

MCP23008 ( PinName  sda,
PinName  scl,
int  i2cAddress 
)

Constructor for the MCP23008 connected to specified I2C pins at a specific address.

8-bit I/O expander with I2C interface

Parameters:
sdaI2C data pin
sclI2C clock pin
i2cAddressI2C address

Definition at line 29 of file MCP23008.cpp.


Member Function Documentation

void config ( unsigned char  dir_config,
unsigned char  pullup_config,
unsigned char  polarity_config 
)

Configure an MCP23008 device.

Parameters:
dir_configdata direction value (1 = input, 0 = output)
pullup_config100k pullup value (1 = enabled, 0 = disabled)
polarity_configpolarity value (1 = flip, 0 = normal)

Definition at line 67 of file MCP23008.cpp.

int read_bit ( int  bit_number )

Read a 0/1 value from an input bit.

Parameters:
bit_numberbit number range 0 --> 7
Returns:
0/1 value read

Definition at line 150 of file MCP23008.cpp.

int read_mask ( unsigned char  mask )

Read a 8-bit value from the device and apply mask.

Parameters:
mask8-bit mask value
Returns:
8-bit data with mask applied

Definition at line 125 of file MCP23008.cpp.

void reset ( void   )

Reset MCP23008 device to its power-on state.

Definition at line 39 of file MCP23008.cpp.

void write_bit ( int  value,
int  bit_number 
)

Write a 0/1 value to an output bit.

Parameters:
value0 or 1
bit_numberbit number range 0 --> 7

Definition at line 136 of file MCP23008.cpp.

void write_mask ( unsigned char  data,
unsigned char  mask 
)

Write a masked 16-bit value to the device.

Parameters:
data8-bit data value
mask8-bit mask value

Definition at line 116 of file MCP23008.cpp.