You are viewing an older revision! See the latest version
PCA9675_IO_Expander
PAC9675 IO Expander¶
The PCA9675 is an I2C based device with 16 quasi bidirectional IO pins configurable as either input or output. The 16 pins are each capable of sinking 25mA when driving loads and is therefore useful as an LED driver. The IO pins can also be turned into input mode as well as be used to read digital inputs from switches.
It is important when driving this device to ensure that the correct IO configuration is set as a pin configured for output mode could contest with an input signal. The worst case scenario is when a digital input pin is has a logic 1 applied to it and the pin is inadvertantly driven as an output with logic 0 output. In this scenario a high level of current will flow into the device, causing possible damage.
With this suite of software a class has been created for the PCA9675. This object class allows the user to select which I2C peripheral he wants to use with the device and to also to assign a custom I2C slave address. The slave address must be the same as what is configured in hardware for the device, but the C++ class does allow for multiple objects/devices connected to the same I2C bus.
To use the class the user must first include the relevant header files:
#include "mbed.h" #include "misra_types.h" /* MISRA Types */ #include "PCA9675.h"
and then create an I2C object on which the PCA9675 will sit
I2C CNTRL_i2c(p9, p10);
In this case the I2C object is called CNTRL_i2c and uses pins p9 and 10 on the mbed module. Secondly the user must then create the object for the PCA9675 specifying which I2C bus he wants to use and the I2C slave address for the device
PCA9675 BaseBoardLatch(&CNTRL_i2c, PCA9675_BASE_BOARD_SLAVE_ADDRESS);
Here the object is called BaseBoardLatch, the I2C bus used in the one we have just created called CNTRL_i2c, and the slave address is referenced via a #define. Once this is done you can read the identifty information contained within the device. This is included in each part and is accessed via an I2C sequence described in detail in the datasheet for the device. The ID information consists of the manufacturers identity, the part identity and the device revision. Each manufacturer has its own unique id (0 in the case of NXP). Reading this information initially will give you some confidence that the I2C is working correctly and you can communiate with the device. The public function looks like this:
sint32_t read_device_ID(uint8_t *manufacturer, uint16_t *part_ident, uint8_t *die_revision);
The manufacturer ID is 8 bits wide, the part_ident is 13 bits wide and the die revision information is 3 bits wide. Hence using 8, 16 and 8 bit unsigned integers respectively will be sufficeient to hld the data. The return value for the function is 0 is the device has been accessed successfully (ACK) otherwise a non zero number is returned (NACK). An enum can be used to reference the return value. It's name is eI2C_ACK. The calling function can use the comparison with objectname.enumvalue (BaseBoardLatch.eI2C_ACK in this case) to determie if the call has been successful or not.