Skip to content

PCA9535 16-Bit I/O Expander

lbuild module: modm:driver:pca9535

Also software-compatible with PCA9555. The lower three address bits can be configured: 0100abc.

Notice that you can specify multiple pins at the same time for functions with argument type Pins, either by ORing the according pins, or converting a 16-bit value using the Pins(uint16_t) converting constructor.

Other functions with argument type Pin can only take one pin. If you want to operate on all 16-bit, use the get(Inputs|Outputs|Directions|Polarities)() getters.

using Pin = expander.Pin;
using Pins = expander.Pins;

expander.setOutput(Pins(0xff); // set all lower 8 pins to output
expander.set(Pin::P0_0);       // set only pin 00 high
expander.reset(Pin::P0_1 | Pin::P0_2); // reset 2 pins
expander.toggle(Pin::P0_3 | Pin::P0_4 | Pin::P0_5);    // toggle 3 pins

expander.readInput();  // transfer input states from the external chip
bool high = expander.read(Pin::P1_0);    // check a single pin

Pins input = expander.getInputs();   // get all 16 input states
bool isAnyPinHigh = input.any(Pin::P1_1 | Pin::P1_2 | Pin::P1_3); // check if any of 3 pins is high

Dependencies

modm:driver:pca9535 modm_driver_pca9535 modm: driver: pca9535 modm_architecture_fiber modm: architecture: fiber modm_driver_pca9535->modm_architecture_fiber modm_architecture_gpio_expander modm: architecture: gpio.expander modm_driver_pca9535->modm_architecture_gpio_expander modm_architecture_i2c_device modm: architecture: i2c.device modm_driver_pca9535->modm_architecture_i2c_device modm_architecture_register modm: architecture: register modm_driver_pca9535->modm_architecture_register modm_math_utils modm: math: utils modm_driver_pca9535->modm_math_utils