6.1.4 SPI_Exchange Command and its Response
The SPI_Exchangecommand (0x2C) initiates a full-duplex SPI
transaction. The command writes wDatLen bytes from
vWrDtPac to the SPI client device while simultaneously reading
wDatLen bytes.
This command is sent through Endpoint 0x06 (OUT). The response is read through Endpoint 0x86 (IN).
If the exchange data length exceeds the payload capacity of a single USB packet, multiple packets are used. The first packet contains up to 60 write data bytes, and each additional continuation packet contains up to 62 write data bytes.
| Serial No. | Byte Index | Command | Description | |
|---|---|---|---|---|
| 1 | 0 | 0x2C | Command code | Initiates a full-duplex SPI 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 | ... | ... | |
| 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 | 0x2C | Repeat command code | The exchange is continued | |
| 67 | 1 | 0xA0 | The exchange is continued | |
| 68 | 2 | b60(vWrDtPac) | The 61st data byte | The next 62 data bytes |
| 69-126 | ... | ... | Additional data bytes | |
| 127 | 63 | b121(vWrDtPac) | The 122nd data byte | |
| 128 | Wait for the next response, which includes the data bytes read, and read them | |||
| 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 | Read the final response | |||
| Byte Index | Response | Description | |
|---|---|---|---|
| 0 | 0x2C | Returns command code | Returns whether the SPI_Exchange command was
accepted |
| 1 | 0x22 | Accepted – initiated | The command is accepted, and a full-duplex SPI transaction is initiated |
0x60 | Rejected – wrong parameters | The command is rejected because parameters are invalid | |
0x64 | Rejected – SPI is busy | The command is rejected because the SPI module is busy | |
| Byte Index | Response | Description | |
|---|---|---|---|
| 0 | 0x2C | Returns command code | The SPI full-duplex transaction is continued |
| 1 |
|
Exchange is continued | |
| 2 | L(wDatLen) | Data length (lower byte) | Number of data bytes. Maximum length: 65,535 bytes |
| 3 | H(wDatLen) | Data length (upper byte) | |
| 4 | b0(vRdDtPac) | First data byte | The first 60 bytes are read |
| 5 | b1(vRdDtPac) | Second data byte | |
| ... | ... | ... | |
| 63 | b59(vRdDtPac) | The 60th data byte | |
| Byte Index | Response | Description | |
|---|---|---|---|
| 0 | 0x2C | Return command code | The SPI full-duplex transaction is continued |
| 1 |
| Exchange is continued | |
| 2 | b60(vRdDtPac) | The 61st data byte | The next 62 data bytes are read |
| ... | ... | ... | |
| 63 | b121(vRdDtPac) | The 122nd data byte | |
| The subsequent response sequence is repeated until all requested bytes have been exchanged | |||
