6.1.2 SPI_Write Command and its Response
The SPI_Write command (0x24) initiates an SPI write
transaction. The command writes wDatLen bytes of data,
vWrDtPac, to the SPI client device selected by the active SPI
configuration.
This command is sent through Endpoint 0x06 (OUT). The response is read through Endpoint 0x86 (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 packet containing up to 62 data bytes.
A response is provided after the initial command packet, after each continuation packet, and after the write transaction completes.
| Serial No. | Byte Index | Command | Description | |
|---|---|---|---|---|
| 1 | 0 | 0x24 | Command code | Initiates the SPI write transaction |
| 2 | 1 | 0xAF | Command code extension byte | |
| 3 | 2 | L(wDatLen) | Data length (lower byte) | Number of data bytes. Maximum length: 65,535 bytes |
| 4 | 3 | H(wDatLen) | Data length (upper byte) | |
| 5 | 4 | b0(vWrDtPac) | First data byte | The first 60 bytes |
| 6 | 5 | b1(vWrDtPac) | Second data byte | |
| 7-63 | 6-62 | ... | Additional data bytes | |
| 64 | 63 | b59(vWrDtPac) | The 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 | 0x24 | Repeat 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 | 3-62 | ... | Additional data bytes | |
| 127 | 63 | b121(vDatPac) | The 122nd data byte | |
| 128 | Wait for the next response | |||
| 129 | If all data bytes are not 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 | Response | Description | |
|---|---|---|---|
| 0 | 0x24 | Return command code | Returns whether the SPI_Write command was accepted |
| 1 | 0x22 | Accepted - initiated | The command is accepted, and an SPI write is initiated |
0x60 | Rejected – wrong parameters | The command is rejected because the parameters are invalid | |
0x64 | Rejected – SPI is busy | The command is rejected because the SPI module is busy | |
| Byte Index | Response | Description | |
|---|---|---|---|
| 0 | 0x24 | Return command code | The SPI write is continued |
| 1 | 0x22 |
Accepted - write continued | |
0x68 |
Rejected – buffer full | The write buffer is full. Retry the same packet until it is accepted. | |
0x20 |
Success – write completed | The SPI_Write transaction is completed | |
