How to Write and Read Registers within TCAL6416 IO Expander

TCAL6416 I2C IO Expander is like any I2C target. It has a device address (target address) and several register addresses known as “command bytes” in the digital core of the device.

The device address (target address) is different from a register address. You can think of the target address as referring to the TCAL6416 IO expander itself. The register address refers to the contents and configurations inside the TCAL6416.

Command Byte Table of TCAL6416

Complete Command Byte Table 7-5 on page 26/55 of the TCAL6416 Datasheet

In order to talk to the TCAL6416, you would need to send address 0x20 or 0x21 since these are the two address combinations provided by the IC.

In order to change the configuration of the IO expander, you would need to talk to a specific register inside the TCAL6416. For example, if you wanted to change the output drive strength on port 0, you would send register address 0x40 or 0x41.

Example Write:

Writing to the TCAL6416 IO expander can be found in the example on page 30 of the datasheet in figure 7-9.

Writing to the Output Port Registers - TCAL6416

Figure 7-9 Write to Output Port Registers

Figure 7-9 walks through an example of writing data to the output port 0 register (P07 - P00) and output port 1 register (P17 - P10). This shows how to set the output logic of all 16 GPIO’s that are configured as an OUTPUT.

The following is the bit by bit description of what is being written:

  1. Start Condition (S) - From Controller

  2. Target (Device) Address - 0x20 or 0x21 (depending on ADDR bit)

  3. Write Bit (0)

  4. ACK - Comes from the Target Device

  5. Command Byte Address (0x02 = 0b0000010) - this points to the output port register 0 from the command byte table 7-5 on page 26 of the datasheet

  6. ACK - Comes from the Target Device

  7. Data to Output Port 0 - this is the data that sets the output logic high or low on the Pxx output pins (P07 - P00)

  8. ACK - Comes from the Target Device

  9. Data to Output Port 1 - this is the data that sets the output logic high or low on the Pxx output pins (P17 - P10)

  10. Stop Condition (P) - From Controller

Example Read:

The example read command comes from figure 7-11 on page 31 of the datasheet.

Reading From Register - TCAL6416

Figure 7-11 Read From Register on page 31 of the TCAL6416 Datasheet

The following is the bit by bit description of how a read transaction works:

  1. Start Condition (S) - From Controller

  2. Target (Device) Address - 0x20 or 0x21 (depending on ADDR bit)

  3. Write Bit (0) - This is a “0” because we need to first set the command byte address (pointer address) we want to read data from

  4. ACK - Comes from the Target Device

  5. Command Byte Address From Table 7-5

  6. ACK - Comes from the Target Device

  7. Repeated Start (S or Sr)

  8. Target (Device) Address - 0x20 or 0x21 (depending on ADDR bit) - must send target address again

  9. Read Bit (1) - Since we set the command byte (pointer address) with a write bit, we now want to read from the target address so we can read data from the command byte register address.

  10. ACK - Comes from the Target Device

  11. Data (MSB to LSB) - this is the data read from the command byte address

  12. ACK - Come from the Controller Device

  13. the Controller can continue to read repeated data from the register address until a NACK is issued by the controller

  14. NACK - Comes from the Controller Device - tells the TCAL6416 to stop data read

  15. Stop Condition (P) - From Controller

Next
Next

The SPI Resource Guide