NXP PCA9532
The PCA9532 is a 16-bit I2C-bus and SMBus I/O expander optimized for dimming LEDs in 256 discrete steps for Red/Green/Blue (RGB) color mixing and
back light applications. The driver is implemented in source files pca9532.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/pca9532.h"
#include <assert.h>
static I2C i2c; /* Allocate an I2C port for communicating with the device */
static PCA9532 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 = PCA9532_Open(&driver, /* Open the driver */
&i2c, /* Provide the I2C port to be used by the driver */
0); /* The bottom address value (A0-A2 on board) */
assert(status == SUCCESS);
}
The snippet below shows how to read and write the pin values to the device.
PCA9532_ReadPins(&driver, &pins); /* Read the current state of the pins on the device */
PCA9532_WritePins(&driver, 0); /* Write all pins to high-impedance (LED off) */
/* When writing the pin values, each pin state
is represented by 2-bits (thus the values below) */
PCA9532_WritePins(&driver, 0x55555555); /* Write all pins to low (LED on) */
PCA9532_WritePins(&driver, 0xAAAAAAAA); /* Write all pins to blink at PWM0 rate */
PCA9532_WritePins(&driver, 0xFFFFFFFF); /* Write all pins to blink at PWM1 rate */
Examples
The demo projects for the following boards provide an example of the usage of this driver.
API Reference
STATUS PCA9532_Open(PCA9532* driver, I2C* port, BYTE addr)
Creates and initializes a driver for the NXP PCA9532 LED dimmer.
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 value of the external address pins (3 lower bits A0-A2). |
SUCCESS | The driver has been initialized and is ready for communications. |
ERR_NULLREFERENCE | The argument 'driver' or 'port' was found to be NULL. |
STATUS PCA9532_SetTimeout(PCA9532* 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. |
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 PCA9532_Read(PCA9532* driver, BYTE reg, void* buf, UINT32 nbytes)
Reads and returns register values from the device.
PARAMETERS
driver | A pointer to the driver to be used. |
reg | The register address to be read. Valid registers are 0 thru 9. Set the auto-increment bit (bit 4) if reading more than a single register. |
buf | A pointer to a caller allocated buffer to receive the returned values. |
nbytes | The number of bytes to be read from the device. |
SUCCESS | The register values have been read and returned. |
ERR_NULLREFERENCE | The argument 'driver' or 'buf' was found to be NULL. |
STATUS PCA9532_Write(PCA9532* driver, void* data, UINT32 nbytes)
Writes values to the registers within the device.
PARAMETERS
driver | A pointer to the driver to be used. |
data | A pointer to the data to be written to the device. The first byte is the starting register address to be
written. Set the auto-increment bit (bit 4) for this byte if writing more than a single register. |
nbytes | The number of bytes to be written to the device. |
SUCCESS | The values have been written to the device. |
ERR_NULLREFERENCE | The argument 'driver' or 'data' was found to be NULL. |
STATUS PCA9532_SetPrescalar(PCA9532* driver, BYTE ch, BYTE value)
Sets a new prescalar value for a channel within the device.
PARAMETERS
driver | A pointer to the driver to be used. |
ch | The prescalar channel to be set (0 or 1). |
value | The new prescalar value (0-255). |
SUCCESS | The new prescalar value has been set. |
ERR_NULLREFERENCE | The argument 'driver' was found to be NULL. |
ERR_NOTSUPPORTED | The specified prescalar channel is not supported. |
STATUS PCA9532_SetPWM(PCA9532* driver, BYTE ch, BYTE value)
Sets a new pulse width modulation (PWM) value for a channel within the device. The outputs are low (LED on) when the count is less
than this value and high (LED off) when it is greater.
PARAMETERS
driver | A pointer to the driver to be used. |
ch | The prescalar channel to be set (0 or 1). |
value | The new PWM value (0-255). |
SUCCESS | The new PWM value has been set. |
ERR_NULLREFERENCE | The argument 'driver' was found to be NULL. |
ERR_NOTSUPPORTED | The specified PWM channel is not supported. |
STATUS PCA9532_ReadPins(PCA9532* driver, UINT16* value)
Reads and returns the 16 pin states from the device.
PARAMETERS
driver | A pointer to the driver to be used. |
value | A pointer to a caller allocated value to receive the returned pin states. |
SUCCESS | The pin states have been read and returned. |
ERR_NULLREFERENCE | The argument 'driver' or 'value' was found to be NULL. |
STATUS PCA9532_WritePins(PCA9532* driver, UINT32 value)
Writes all 16-pin states to the device.
PARAMETERS
driver | A pointer to the driver to be used. |
value | The 32-bit representation of all 16-pin states. Each pin state is 2-bits wide with
the following definition.
0 | Pin output is high impedance (LED off, default). |
1 | Pin output is low (LED on). |
2 | Pin output blinks at PWM0 rate. |
3 | Pin output blinks at PWM1 rate. |
|
SUCCESS | The new pin states have been set. |
ERR_NULLREFERENCE | The argument 'driver' was found to be NULL. |