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:

  1. Configure the SPI interface:
    • Send SPI_Configure command through Endpoint 0x06, OUT with the following parameters:
      ParameterValueDescription
      Command0x20Configure the SPI
      Clock speed0x30

      0x20

      0x32

      0x22

      0x34

      0x24

      0x26

      12 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 mode0x44

      0x45

      0x46

      0x47

      SPI mode 0

      SPI mode 1

      SPI mode 2

      SPI mode 3

      Chip-select and its active state

      0x00

      0x01

      0x40

      0x41

      0x80

      0x81

      0xC0

      0xC1

      CS0 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

      0x0000

      0x000A

      0x0014

      0x03E8

      0x1388

      0 μs

      10 μs

      20 μs

      ...

      1 ms

      ...

      5 ms

  • Read the response through Endpoint 0x86 (IN). The response can be one of the following:
    • Response codeStatusAction
      0x20Response to SPI ConfigContinue reading
      0x20

      0x60

      0x64

      The SPI interface is configured.

      Invalid parameters.

      The SPI module is busy.

      Proceed to the write transaction.

      Retry with valid parameters.

      Wait and retry later.

Write transaction
  • Send the SPI_Write command through Endpoint 0x06 (OUT) with the following parameters:
ParameterValueDescription
Command0x24Write to the SPI client device
0xAF
Write data lengthwDatLenNumber of bytes to be written including the location address, encoded as a 16-bit hexadecimal value
Location addressvLocAddStarting location from where the data should be written
Data bytesvWrDtPacData to write (up to 60 bytes, including the location address)
  • Read the response from Endpoint 0x86 (IN). Possible initial responses are:
    Response codeStatusAction
    0x24Response to SPI WriteContinue reading
    0x22

    0x60

    0x64

    The 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:
    ParameterValueDescription
    Command0x24Write to the SPI client device is continued.
    Continuation flag0xA0
    Data bytesvWrDtPacData 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 codeStatusAction
    0x24

    NACK

    Response to SPI Write.

    No response available yet.

    Continue reading.

    Continue polling.

    0x22

    0x68

    0x20

    The 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:

  1. Configure the SPI interface:
    • Refer to the Configure SPI section of Writing to an SPI client device from a specified location.
  2. Read data from the specific locations of a SPI client device.
    • Send the SPI_Exchange command through Endpoint 0x06 (OUT), with the following parameters:
      ParameterValueDescription
      Command0x2CWrite to and read from an SPI client device
      0xAF
      Read data length + 1 + bytes in the location addresswDatLen + 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 commandbRdComndThe read command specified by the SPI client device.
      Location addressvLocAddStarting 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 codeStatusAction
      0x2CResponse to SPI ExchangeContinue reading.
      0x22

      0x60

      0x64

      SPI 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:
      ParameterValueDescription
      Command0x2CThe exchange transaction is continued.
      Continuation flag0xA0
      62 bytes of dummy data0x00Dummy write (up to 62 bytes).
      • Read the response from Endpoint 0x86 (IN). The response can be one of the following:
        Response codeStatusAction
        0x2C

        NACK

        Response to SPI Exchange.

        No response available yet.

        Continue reading.

        Continue polling.

        0x21

        0x68

        The 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 readContinue 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:
        ParameterValueDescription
        Command0x2CThe exchange transaction is continued.
        Continuation flag0xA0
        62 bytes of dummy data0x00Dummy write (up to 62 bytes)
      • Keep polling Endpoint 0x86 (IN) until final read data is returned. Possible poll results:
      Response codeStatusAction
      0x2C

      NACK

      Response 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 readRead all the data bytes available in the Endpoint