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.
| SI. No. | Byte Index | Command | Description | |
|---|---|---|---|---|
| 1 | 0 | 0x4A | Command code | Initiates the I2C write-read transaction |
| 2 | 1 | bAddress | I2C client address | 7-bit I2C client address |
| 3 | 2 | L(wWrDtLen) | Write data length (lower byte) | Number of data bytes to be written; maximum length 65535 bytes |
| 4 | 3 | H(wWrDtLen) | Write data length (upper byte) | |
| 5 | 4 | L(wRdDtLen) | Read data length (lower byte) | Number of data bytes to be read; maximum length 65535 bytes |
| 6 | 5 | H(wRdDtLen) | Read data length upper byte | |
| 7 | 6 | b0(vDatPac) | First data byte | The 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. |
| 8 | 7 | b1(vDatPac) | Second data byte | |
| 9 | … | … | ... | |
| 10 | n+5 | bn-1(vDatPac) | The Nth data byte | |
| 11 | Wait for the first response to determine whether the command was accepted | |||
| 12 | If accepted, continue polling for read data until all requested bytes are received or an error occurs. | |||
| Byte Index | Response | Description | |
|---|---|---|---|
| 0 | 0x4A | Return command code | Returns whether the I2C_WriteRead command was
accepted. |
| 1 | 0x22 | Accepted – initiated | The command is accepted, an I2C write is initiated, and then an I2C read is performed. |
0x60 | Rejected – wrong parameters | The command is rejected because the parameters are invalid | |
0x64 | Rejected – I2C is busy | The command is rejected because the I2C module is busy | |
| Byte Index | Second Response | Description | |
|---|---|---|---|
| 0 | 0x4A |
Return command code | The I2C_WriteRead command is continued |
| 1 |
|
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 | |
| 2 | L(wRdDtLen) | Read data length (lower byte) | Number of data bytes to be read (maximum 65,535 bytes) |
| 3 | H(wRdDtLen) | Read data length (upper byte) | |
| 4 | b0(vDatPac) | First data byte | The first 60 data bytes are read |
| 5 | b1(vDatPac) | Second data byte | |
| … | … | ... | |
| 63 | b59(vDatPac) | The 60th data byte | |
| Byte Index | Subsequent Response | Description | |
|---|---|---|---|
| 0 | 0x4A |
Return command code | The I2C_WriteRead command is continued |
| 1 |
|
The I2C_WriteRead operation is continued | |
|
|
Failure - clock-stretch timeout | A clock-stretch timeout occurred | |
|
|
Failure - arbitration lost | Bus arbitration was lost | |
| 4 | b60(vDatPac) | The 61st data byte | The next 62 data bytes are read |
| ... | ... | ... | |
| 63 | b121(vDatPac) | The 122nd data byte | |
| The subsequent response sequence is repeated until all requested bytes have been received or an error occurs | |||
