Helper module for controlling an MCP23018 I/O expander via I2C. Depends on the i2chelper.h module.
NOTE: If the macro MCP23018_BANK_MODE is defined, the I/O expander is assumed to operate in banked mode (i.e. all registers for the same I/O port are located together in the expander’s register address space). If MCP23018_BANK_MODE is NOT defined, the I/O expander is assumed to operate in paired mode (i.e. all registers of the same type are located together). Consult your expander’s datasheet for details on the different addressing modes.
mcp23018.h | Helper module for controlling an MCP23018 I/O expander via I2C. |
Macros | |
MCP23018_MAX_PAIR | The largest valid register pair address. |
MCP23018_MAX_BANK | The largest valid register bank address. |
MCP23018_REG_MASK | Bit mask for the valid bits of an MCP23018 register address. |
Enumerations | |
MCP23018 IOCON Bit Numbers | An MCP23018 can be reconfigured by setting these bits in the IOCON register. |
MCP23018 Register Addresses | These registers are used to configure and perform I/O with an MCP23018 via I2C. |
Variables | |
mcp23018_reg | The type of MCP23018 register addresses. |
Functions | |
mcp23018_is_valid_reg | Register address validator. |
mcp23018_begin_read | Starts an asynchronous register read operation. |
mcp23018_poll_read | Tests whether there is an ongoing I2C operation. |
mcp23018_read | Performs a synchronous register read operation. |
mcp23018_begin_write | Starts an asynchronous register write operation. |
mcp23018_write | Performs a synchronous register write operation. |
An MCP23018 can be reconfigured by setting these bits in the IOCON register.
These registers are used to configure and perform I/O with an MCP23018 via I2C.
NOTE: The IODIRx registers are set to all ones (i.e. all inputs) on startup/reset. All other registers are zeroed on startup/reset.
NOTE: Entries where the register name ends with an ‘x’ describe two registers, one for the ‘A’ port and one for the ‘B’ port, named correspondingly.
typedef uint8_t mcp23018_reg
The type of MCP23018 register addresses.
NOTE: Bits that are set to zero in MCP23018_REG_MASK are zero in all valid register addresses.
i2c_state mcp23018_begin_read( i2c_slave_addr addr, mcp23018_reg r )
Starts an asynchronous register read operation. This function delegates to i2chelper_request and completion of the register read can be detected as described in the documentation of that function.
addr | 7-bit I2C slave address of the target device. The address MUST be stored in the 7 least significant bits of the argument and MUST NOT include an R/W control bit. |
r | Address of the register to read. |
I2C_ACTIVE if and only if the register read operation was successfully started, otherwise an error code.
i2c_state mcp23018_poll_read( uint8_t * v )
Tests whether there is an ongoing I2C operation. If there is no ongoing operation, this function will output the most recently read MCP23018 register value.
CAUTION: This function does not check whether any MCP23018 register read operation has actually been started.
v | Pointer to memory where the most recently read register value should be stored. This output parameter is updated only when the returned i2c_state is I2C_READY. |
An i2c_state value representing the current state of the I2C module.
i2c_state mcp23018_read( i2c_slave_addr addr, mcp23018_reg r, uint8_t * v )
Performs a synchronous register read operation.
addr | 7-bit I2C slave address of the target device. The address MUST be stored in the 7 least significant bits of the argument and MUST NOT include an R/W control bit. |
r | Address of the register to read. |
v | Pointer to memory where the result of the read register operation should be stored. This output parameter is updated only when the returned i2c_state is I2C_READY. |
I2C_READY if and only if the register read operation was successfully performed, otherwise an error code.
i2c_state mcp23018_begin_write( i2c_slave_addr addr, mcp23018_reg r, uint8_t v )
Starts an asynchronous register write operation. This function delegates to i2chelper_request and completion of the register write can be detected as described in the documentation of that function.
addr | 7-bit I2C slave address of the target device. The address MUST be stored in the 7 least significant bits of the argument and MUST NOT include an R/W control bit. |
r | Address of the register to write to. |
v | Value to write to the target register. |
I2C_ACTIVE if and only if the register read operation was successfully started, otherwise an error code.
i2c_state mcp23018_write( i2c_slave_addr addr, mcp23018_reg r, uint8_t v )
Performs a synchronous register write operation.
addr | 7-bit I2C slave address of the target device. The address MUST be stored in the 7 least significant bits of the argument and MUST NOT include an R/W control bit. |
r | Address of the register to write to. |
v | Value to write to the target register. |
I2C_READY if and only if the register write operation was successfully performed, otherwise an error code.
The type of MCP23018 register addresses.
typedef uint8_t mcp23018_reg
Register address validator.
uint8_t mcp23018_is_valid_reg( mcp23018_reg r )
Starts an asynchronous register read operation.
i2c_state mcp23018_begin_read( i2c_slave_addr addr, mcp23018_reg r )
Tests whether there is an ongoing I2C operation.
i2c_state mcp23018_poll_read( uint8_t * v )
Performs a synchronous register read operation.
i2c_state mcp23018_read( i2c_slave_addr addr, mcp23018_reg r, uint8_t * v )
Starts an asynchronous register write operation.
i2c_state mcp23018_begin_write( i2c_slave_addr addr, mcp23018_reg r, uint8_t v )
Performs a synchronous register write operation.
i2c_state mcp23018_write( i2c_slave_addr addr, mcp23018_reg r, uint8_t v )
Initiates an I2C request operation consisting of a transmit phase followed by a receive phase.
i2c_state i2chelper_request( i2c_slave_addr addr, uint8_t n_out, volatile const uint8_t * bfr_out, uint8_t n_in, volatile uint8_t * bfr_in )
The type of state and result codes for the I2C module.
typedef uint8_t i2c_state