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.

Table 6-11. SPI_Exchange - Command
Serial No.Byte IndexCommandDescription
100x2CCommand codeInitiates a full-duplex SPI transaction
210xAFCommand code extension byte
32L(wDatLen)Data length (lower byte)Number of data bytes. Maximum length: 65,535 bytes.
43H(wDatLen)Data length (upper byte)
54b0(vWrDtPac)First data byteThe first 60 bytes
65b1(vWrDtPac)Second data byte
7-636-62......
6463b59(vWrDtPac)The 60th data byte
65Wait 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.

660x2CRepeat command codeThe exchange is continued
6710xA0The exchange is continued
682b60(vWrDtPac)The 61st data byteThe next 62 data bytes
69-126......Additional data bytes
12763b121(vWrDtPac)The 122nd data byte
128Wait for the next response, which includes the data bytes read, and read them
129If 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.
130Read the final response
Table 6-12. SPI_Exchange - First Response
Byte IndexResponseDescription
00x2CReturns command codeReturns whether the SPI_Exchange command was accepted
10x22Accepted – initiatedThe command is accepted, and a full-duplex SPI transaction is initiated
0x60Rejected – wrong parametersThe command is rejected because parameters are invalid
0x64Rejected – SPI is busyThe command is rejected because the SPI module is busy
Table 6-13. SPI_Exchange - Second Response
Byte IndexResponseDescription
00x2CReturns command codeThe SPI full-duplex transaction is continued
1

0x21

Exchange is continued

2L(wDatLen)Data length (lower byte)Number of data bytes. Maximum length: 65,535 bytes
3H(wDatLen)Data length (upper byte)
4b0(vRdDtPac)First data byteThe first 60 bytes are read
5b1(vRdDtPac)Second data byte
.........
63b59(vRdDtPac)The 60th data byte
Table 6-14. SPI_Exchange - Subsequent Response After Packet Data is Read
Byte IndexResponseDescription
00x2CReturn command codeThe SPI full-duplex transaction is continued
1

0x21

Exchange is continued
2b60(vRdDtPac)The 61st data byteThe next 62 data bytes are read
.........
63b121(vRdDtPac)The 122nd data byte
The subsequent response sequence is repeated until all requested bytes have been exchanged