How Do I Write and Read from Different Registers of an I2C Device?

Question from the Customer:

I am using the Aardvark I2C/SPI Host Adapter with an I2C device. I need to read and write to specific registers, such as:

  • Write to register 0x2H
  • Read from register 0x3H

How can I best approach this task?

Response from Technical Support:

Thanks for your question! For writing and reading to a register, we recommend using our free application, Control Center Serial Software, in batch mode.

Using Control Center Serial Software

When using the GUI dialog, the register read operation in the Control Center Serial Software is streamlined. The I2C write and I2C read transactions are combined, which makes this operation easier for the user. However, that method does not supporting writing to and then reading from different registers.  In batch mode, you can easily write more detailed scripts, such as writing to one register address and reading from another register address.

Read/Write Registers in Batch Mode

For example, to read 4 bytes from register address 0x11 on I2C slave 0x55, you can do the following.

<i2c_write addr="0x55" count="1" nostop="1" radix="hex">11</i2c_write>

f<i2c_read addr=" count="4"/>

Shown below is an example of a full I2C transaction that is sent on the I2C bus for master register write/read.

Master Register Write:

<START><I2C_SLAVE_ADDR with WR_CMD><REGISTER_OFFSET><WR_DATA0><WR_DATA1>...<STOP>

Master Register Read:

<START><I2C_SLAVE_ADDR with WR_CMD><REGISTER_OFFSET><REPEATED_START><I2C_SLAVE_ADDR with RD_CMD><RD_DATA0><DATA1>...<STOP>

The Control Center Serial Software will display the transaction log. To understand the transaction log, we recommend referring to the I2C specification of your target device and compare that information with the sequence shown in the transaction log.

For an example of implementing writing to an I2C device and then reading from a specific register, please refer to the article Which Software Tool Should I Use with the Aardvark I2C/SPI Host Adapter to Read the Status Register Information?

You can also watch an example of using the Control Center Serial Software in batch mode. This video includes writing and implementing an XML script, and watching the transaction log.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.

Request a Demo