NXP PCA9673

The PCA9673 is a 16-bit I2C-bus and SMBus I/O expander with interrupt and reset signals. This driver is implemented in source files pca9673.c/.h and provides communications support with the device over an I²C bus.

Device Information

Basic Usage

The code snippet below shows how to create an instance of the driver and establish communications with the device.

#include "Drivers/NXP/pca9673.h"
#include <assert.h>

static I2C i2c;                             /* Allocate an I2C port for communicating with the device */
static PCA9673 driver;                      /* Allocate an instance of the driver */

void APP_Example(void)
{
    STATUS status;


    status = I2C_Open(&i2c,                 /* Open the I2C port */
                      0,                    /* Port number (0) */
                      400000);              /* Clock rate (400khz) */

    assert(status == SUCCESS);

    status = PCA9673_Open(&driver,          /* Open the driver */
                          &i2c,             /* Provide the I2C port to be used by the driver */
                          0x48);            /* The address value for the device (A6-A0) */

    assert(status == SUCCESS);
}

The code snippet below shows how to read and write the pins of the device.

#include "Drivers/NXP/pca9673.h"
#include <assert.h>

void APP_Example(void)
{
    STATUS status;
    UINT16 value;


    status = PCA9673_Read(&driver, &value);     /* Read the pins of the device */
    assert(status == SUCCESS);

    status = PCA9673_Write(&driver, value);     /* Write the pins of the device */
    assert(status == SUCCESS);
}

API Reference

STATUS PCA9673_Open(PCA9673* driver, I2C* port, BYTE addr)
Creates and initializes a driver for the NXP PCA9673 I/O expander.
PARAMETERS
driver A pointer to a caller allocated driver instance to be initialized.
port A pointer to an open I2C port to be used for communications.
addr The address of the device on the bus (A6-A0).
RETURNS
SUCCESS The driver has been initialized and is ready for communications.
ERR_NULLREFERENCE The argument 'driver' or 'port' was found to be NULL.
STATUS PCA9673_SetTimeout(PCA9673* driver, UINT32 timeout)
Sets a new timeout value, in kernel ticks, to be used for I/O operations. The default is 1000 milliseconds.
PARAMETERS
driver A pointer to the driver to be updated.
timeout The new maximum amount of time, in kernel ticks, to block and wait for I/O operations to complete. Must be larger than zero and use 'INFINITE' to wait indefinitely.
RETURNS
SUCCESS The driver timeout value has been changed.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
ERR_INVALIDARGUMENT The argument 'timeout' must be greater zero.
STATUS PCA9673_Read(PCA9673* driver, UINT16* value)
Reads and returns the pin values from the device.
PARAMETERS
driver A pointer to the driver to be used.
value A pointer to a caller allocated variable to receive the 16-bit port value from the device.
RETURNS
SUCCESS The pin states have been read and returned.
ERR_NULLREFERENCE The argument 'driver' or 'value' was found to be NULL.
STATUS PCA9673_Write(PCA9673* driver, UINT16 value)
Writes the pin values to the device.
PARAMETERS
driver A pointer to the driver to be used.
value The 16-bit port value to be written to the device.
RETURNS
SUCCESS The values have been written to the device.
ERR_NULLREFERENCE The argument 'driver' or 'value' was found to be NULL.