5.1.2 I2C_Write Command and its Response
The I2C_Write command (0x44) initiates an I2C write
transaction. The command writes wWrDtLen bytes of the data,
vDatPac to the I2C client device addressed by
bAddress.
This command is sent through Endpoint 0x03 (OUT). The response is read through Endpoint 0x83 (IN).
If the write data length exceeds the payload capacity of a single USB packet, multiple packets are used. The first packet contains up to 60 data bytes, and each additional continuation packets contains up to 62 data bytes.
A response is provided after the initial command packet, after each continuation packet, and after the write transaction completes or is aborted.
| Serial No. | Byte Index | Command | Description | |
|---|---|---|---|---|
| 1 | 0 | 0x44 | Command code | Initiates the I2C write 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; maximum length: 65,535 bytes |
| 4 | 3 | H(wWrDtLen) | Write data length (upper byte) | |
| 5 | 4 | b0(vDatPac) | First data byte | The first 60 data bytes |
| 6 | 5 | b1(vDatPac) | Second data byte | |
| 7-63 | … | … | Additional data bytes | |
| 64 | 63 | b59(vDatPac) | 60th data byte | |
| 65 | Wait for the first response from the
MCP2222 to determine whether the command is accepted. If the data length is more than 60 bytes, continue writing. | |||
| 66 | 0 | 0x44 | Repeat the command code | Write is continued |
| 67 | 1 | 0xA0 | Write is continued | |
| 68 | 2 | b60(vDatPac) | The 61st data byte | The next 62 data bytes |
| 69-126 | … | … | Additional data bytes | |
| 127 | 63 | b121(vDatPac) | The 122nd data byte | |
| 128 | Wait for the next response | |||
| 129 | If all data bytes have not been written, continue writing by repeating the above steps from serial number 66 to 128 until all data bytes are written. The final packet may contain fewer than 62 data bytes. | |||
| 130 | Continue polling for the write-completion response | |||
| Byte Index | First Response | Description | |
|---|---|---|---|
| 0 | 0x44 | Return command code | Returns whether the I2C Write command was
accepted or rejected |
| 1 | 0x22 | Accepted - initiated | The command is accepted, and an I2C write transaction is initiated |
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 | Subsequent Responses | Description | |
|---|---|---|---|
| 0 | 0x44 | Return command code | The I2C write is continued. |
| 1 |
|
Accepted - write continued | |
|
|
Rejected - buffer full |
The Write buffer is full. Retry sending the same packet until it is accepted. | |
|
|
Failure - address NACK |
An address NACK was received. Verify the I2C client address. | |
|
|
Failure - data NACK |
A data NACK was received. Verify the client device requirements and the data length. | |
|
|
Failure - clock-stretch timeout |
A clock-stretch timeout occurred. Recover the bus and retry, if required. | |
|
|
Failure - arbitration lost |
Bus arbitration was lost; another I2C host may be using the bus. | |
|
|
Success – write completed |
The | |
|
| Failure - bus error | An I2C bus error occurred. | |
