Using I2C Master to write to a device

Typically byte register read/writes are used to configure external I2C controlled hardware.

As an example, assume there is a device connected at address 0x40 (64) with three, single byte, registers. The following commands will write 77 to register 0, 48 to register 1 and 33 to register 2.

vfctrl_usb SET_I2C_WITH_REG 64 0 1 77 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
vfctrl_usb SET_I2C_WITH_REG 64 1 1 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
vfctrl_usb SET_I2C_WITH_REG 64 2 1 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

NOTE: The control protocol does not support variadic (variable number of) arguments. Hence, even when writing a single byte, the full number of arguments must be passed. Unwritten values are ignored.

Using the I2C master to read from a device

To verify the previous I2C register write to register number 0 at address 0x40 (64), an I2C register read can be performed as follows:

vfctrl_usb SET_I2C_READ_HEADER 64 0 1
vfctrl_usb GET_I2C_WITH_REG
> 77 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The byte read is the first of the 56 return values, which in this case, is 77. The following 55 values are undefined since the command only performed a read of 1 register.