6.1.5 SPI Communication Procedure
This section describes the typical command sequence for using the MCP2222 for SPI communication.
Writing to an SPI client device from a specified location:
- Configure the SPI
interface:
- Send SPI_Configure
command through Endpoint 0x06, OUT with the following parameters:
Parameter Value Description Command 0x20Configure the SPI Clock speed 0x300x200x320x220x340x240x2612 MHz clock speed 6 MHz clock speed
3 MHz clock speed
1.5 MHz clock speed
750 kHz clock speed
375 kHz clock speed
187.5 kHz clock speed
SPI mode 0x440x450x460x47SPI mode 0 SPI mode 1
SPI mode 2
SPI mode 3
Chip-select and its active state 0x000x010x400x410x800x810xC00xC1CS0 active low
CS0 active high
CS1 active low
CS1 active high
CS2 active low
CS2 active high
CS3 active low
CS3 active high
Delay between:
- Chip-select assertion and the first data byte
- Each data bytes
- The last data byte and chip-select de-assertion
0x00000x000A0x0014…0x03E8…0x13880 μs
10 μs
20 μs
...
1 ms
...
5 ms
- Send SPI_Configure
command through Endpoint 0x06, OUT with the following parameters:
- Read the response through
Endpoint 0x86 (IN). The response can be one of the following:
-
Response code Status Action 0x20Response to SPI Config Continue reading 0x200x600x64The SPI interface is configured. Invalid parameters.
The SPI module is busy.
Proceed to the write transaction. Retry with valid parameters.
Wait and retry later.
-
- Send the SPI_Write command through Endpoint 0x06 (OUT) with the following parameters:
| Parameter | Value | Description |
|---|---|---|
| Command | 0x24 | Write to the SPI client device |
0xAF | ||
| Write data length | wDatLen | Number of bytes to be written including the location address, encoded as a 16-bit hexadecimal value |
| Location address | vLocAdd | Starting location from where the data should be written |
| Data bytes | vWrDtPac | Data to write (up to 60 bytes, including the location address) |
- Read the response from Endpoint
0x86 (IN). Possible initial responses are:
Response code Status Action 0x24Response to SPI Write Continue reading 0x220x600x64The SPI write transaction is initiated. Invalid parameters.
The SPI module is busy.
Proceed to continue the write transaction. Retry with valid parameters.
Wait and retry later.
-
If the number of data bytes to write exceeds 60 bytes, send continuation packets through Endpoint 0x06 (OUT). Each continuation packet includes:
Parameter Value Description Command 0x24Write to the SPI client device is continued. Continuation flag 0xA0Data bytes vWrDtPacData to write (up to 62 bytes) - After each continuation packet,
and after the write transaction is completed, read the response from Endpoint
0x86 (IN). The response can be one of the following:
Response code Status Action 0x24NACKResponse to SPI Write. No response available yet.
Continue reading. Continue polling.
0x220x680x20The SPI write transaction is continued. The buffer is full.
The SPI write transaction is successfully completed.
Proceed to continue the write transaction. Retry until the packet is accepted.
- Repeat sending the continuation packets through Endpoint 0x06 (OUT) and polling Endpoint 0x86 (IN) until all the required data bytes are written
Reading data from an SPI client device from a specified location:
- Configure the SPI
interface:
- Refer to the Configure SPI section of Writing to an SPI client device from a specified location.
- Read data from the specific
locations of a SPI client device.
- Send the SPI_Exchange
command through Endpoint 0x06 (OUT), with the following parameters:
Parameter Value Description Command 0x2CWrite to and read from an SPI client device 0xAFRead data length + 1 + bytes in the location address wDatLen + 1 + bytes(vLocAdd)The sum of the number of bytes to be read, the bytes in the read command, and the bytes in the location address, encoded as a 16-bit hexadecimal value. SPI client Read command bRdComndThe read command specified by the SPI client device. Location address vLocAddStarting location from where the data should be read (59 - bytes in vLocAdd) bytes of dummy bytes.0x00To generate the SPI clock for reading - Read the initial
response from Endpoint 0x86 (IN). Possible initial responses are:
Response code Status Action 0x2CResponse to SPI Exchange Continue reading. 0x220x600x64SPI Exchange transaction initiated. Invalid parameters.
The SPI module is busy.
Proceed to continue polling for the next response. Retry with valid parameters.
Wait and retry later.
- If the number of data
bytes to read exceeds (59 bytes in
vLocAdd) bytes, send continuation packets through Endpoint 0x06 (OUT). Each continuation packet includes:Parameter Value Description Command 0x2CThe exchange transaction is continued. Continuation flag 0xA062 bytes of dummy data 0x00Dummy write (up to 62 bytes). - Read the
response from Endpoint 0x86 (IN). The response can be one of
the following:
Response code Status Action 0x2CNACKResponse to SPI Exchange. No response available yet.
Continue reading. Continue polling.
0x210x68The SPI exchange transaction is continued. The buffer is full.
Proceed to continue the write transaction. Retry until the packet is accepted.
wDatLenThe first 60 bytes of data are read Continue reading vRdDtPacRead all the data bytes available in the Endpoint. Continue sending continuation packet until all packets are read.
- Repeat
sending continuation packet through Endpoint 0x06 and
polling the response packets through Endpoint 0x86 until the
required data bytes are read:
Parameter Value Description Command 0x2CThe exchange transaction is continued. Continuation flag 0xA062 bytes of dummy data 0x00Dummy write (up to 62 bytes)
- Keep polling Endpoint 0x86 (IN) until final read data is returned. Possible poll results:
Response code Status Action 0x2CNACKResponse to SPI Exchange. No response available yet.
Continue reading. Continue polling.
0x21The SPI Read transaction is continued. Continue reading until the entire packet is read. vRdDtPacThe next 62 bytes of data are read Read all the data bytes available in the Endpoint - Read the
response from Endpoint 0x86 (IN). The response can be one of
the following:
- Send the SPI_Exchange
command through Endpoint 0x06 (OUT), with the following parameters:
