White Papers

6
ACCESS THE GPIO CONTROLLER
The TI TCA9555 provides 16 GPIO pins, with 12 connected to the Embedded PC 3000 Input and Output pins (DI0-5, DO0-5) as
described in previous sections. The remaining 4 pins are unconnected. Each can be configured as an input or an output pin. The TI
TCA9555 presents several couples of two 8-bit registers (i.e. 16 bits in each couple) with each couple dedicated to input, output and
more. To simplify the programming model, the read/write byte operations on a couple of 8-bit register will be combined into a single 16-
bit operation.
The following source code example implements the functions for reading and writing 16-bit words from and to the I2C bus via IOCTL.
int smbus_read_word(int fd, int reg, __u16 *word)
{
union i2c_smbus_data data;
struct i2c_smbus_ioctl_data ioctl_data;
int rc;
ioctl_data.read_write = I2C_SMBUS_READ;
ioctl_data.command = reg;
ioctl_data.size = I2C_SMBUS_WORD_DATA;
ioctl_data.data = &data;
rc = ioctl(fd, I2C_SMBUS, &ioctl_data);
if (rc)
fprintf(stderr, "Failed to read word from SMBUS\n");
else
*word = data.word;
return rc;
}
int smbus_write_word(int fd, int reg, __u16 word)
{
union i2c_smbus_data data;
struct i2c_smbus_ioctl_data ioctl_data;
int rc;
ioctl_data.read_write = I2C_SMBUS_WRITE;
ioctl_data.command = reg;
ioctl_data.size = I2C_SMBUS_WORD_DATA;
ioctl_data.data = &data;
data.word = word;
rc = ioctl(fd, I2C_SMBUS, &ioctl_data);
if (rc)
fprintf(stderr, "Failed to write word to SMBUS\n"”);
return rc;
}
THE REGISTERS ON GPIO CONTROLLER
The TI TCA9555 consists of four couples of 8-bit registers. From the programmer’s perspective, there are four 16-bit registers
comprising of configuration, input, output, and polarity registers.
Each bit in the configuration register represents the direction, the input or output of a GPIO pin.
Each bit in the output register specifies the level of an output pin to be high or low.
Each bit in the input register indicates the read value of the current level of a GPIO pin.