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.

Table 6-4. SPI_Write - Command
Serial No.Byte IndexCommandDescription
100x24Command codeInitiates the SPI write 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...Additional data bytes
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.

6600x24Repeat command codeWrite is continued
6710xA0Write is continued
682b60(vDatPac)The 61st data byteThe next 62 data bytes
69-1263-62...Additional data bytes
12763b121(vDatPac)The 122nd data byte
128Wait for the next response
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.
130Continue polling for the write-completion response.
Table 6-5. SPI_Write - First Response
Byte IndexResponseDescription
00x24Return command codeReturns whether the SPI_Write command was accepted
10x22Accepted - initiatedThe command is accepted, and an SPI write is initiated
0x60Rejected – wrong parametersThe command is rejected because the parameters are invalid
0x64Rejected – SPI is busyThe command is rejected because the SPI module is busy
Table 6-6. SPI_Write - Subsequent Response After Every Packet Written
Byte IndexResponseDescription
00x24Return command codeThe SPI write is continued
10x22

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