5.1.4 I2C_WriteRead Command and its Response

The I2C_WriteRead command (0x4A) initiates a combined I2C write followed by an I2C read. The command writes wWrDtLen bytes of vDatPac and then reads wRdDtLen bytes from the I2C client device addressed by bAddress.

This command is sent through Endpoint 0x03 (OUT) and the response is read through Endpoint 0x83 (IN).

If the write data length exceeds the available payload space in the first command packet, additional write data is transmitted using continuation packets. A response is available after each transmitted packet.

Table 5-11. I2C_WriteRead - Command
SI. No.Byte IndexCommandDescription
100x4ACommand codeInitiates the I2C write-read transaction
21bAddressI2C client address7-bit I2C client address
32L(wWrDtLen)Write data length (lower byte)Number of data bytes to be written; maximum length 65535 bytes
43H(wWrDtLen)Write data length (upper byte)
54L(wRdDtLen)Read data length (lower byte)Number of data bytes to be read; maximum length 65535 bytes
65H(wRdDtLen)Read data length upper byte
76b0(vDatPac)First data byteThe N (up to 58) data bytes
Note: The write data length can be up to 65,535 bytes. If the length exceeds 58 bytes, use multiple data packets, as done for I2C_Write.
87b1(vDatPac)Second data byte
9...
10n+5bn-1(vDatPac)The Nth data byte
11Wait for the first response to determine whether the command was accepted
12If accepted, continue polling for read data until all requested bytes are received or an error occurs.
Table 5-12. I2C_WriteRead - First Response
Byte IndexResponseDescription
00x4AReturn command codeReturns whether the I2C_WriteRead command was accepted.
10x22Accepted – initiatedThe command is accepted, an I2C write is initiated, and then an I2C read is performed.
0x60Rejected – wrong parametersThe command is rejected because the parameters are invalid
0x64Rejected – I2C is busyThe command is rejected because the I2C module is busy
Table 5-13.  I2C_WriteRead - Second Response
Byte IndexSecond ResponseDescription
00x4A

Return command code

The I2C_WriteRead command is continued
1

0x21

I2C_WriteRead is continued

0x80

Failure - address NACK

An address NACK was received. Verify the I2C client address.

0x88

Failure - clock-stretch timeout

A clock-stretch timeout occurred. Recover the bus and retry, if required.

0x8C

Failure - arbitration lost

Bus arbitration was lost

0x90

Failure - an I2C bus error occurred

A bus error occurred

2L(wRdDtLen)Read data length (lower byte)Number of data bytes to be read (maximum 65,535 bytes)
3H(wRdDtLen)Read data length (upper byte)
4b0(vDatPac)First data byteThe first 60 data bytes are read
5b1(vDatPac)Second data byte
...
63b59(vDatPac)The 60th data byte
Table 5-14.  I2C_WriteRead - Subsequent Response
Byte IndexSubsequent ResponseDescription
00x4A

Return command code

The I2C_WriteRead command is continued
1

0x21

The I2C_WriteRead operation is continued

0x88

Failure - clock-stretch timeout

A clock-stretch timeout occurred

0x8C

Failure - arbitration lost

Bus arbitration was lost
4b60(vDatPac)The 61st data byteThe next 62 data bytes are read
.........
63b121(vDatPac)The 122nd data byte
The subsequent response sequence is repeated until all requested bytes have been received or an error occurs