7.1.5 GPIO Controlling Procedure

This section describes the typical command sequence for using the MCP2222 GPIO functions.

Configure GPIO

Configuring an I/O pin as a normal output pin:

  • Send the IO_SetConfiguration command through Endpoint 0x04 (OUT), with the following parameters:
ParameterValueDescription
Command0x60Configure I/O pin
I/O number0x00

0x10

0x20

...

0x50

IO0

IO1

IO2

...

IO5

I/O setting0x00Refer to the corresponding I/O Setting register for the setting value.
  • Read the response from Endpoint 0x84 (IN). The response can be one of the following:
    Response CodeStatusAction
    0x60Response to the I/O Set ConfigurationContinue reading
    0x20

    0x60

    0x64

    The I/O pin is configured

    Invalid parameters.

    Device configuration is locked.

    Retry with valid parameters.

    Unlock the device configuration and retry.

Configuring an I/O pin as an open-drain output pin:

  • Send the IO_SetConfiguration command through Endpoint 0x04 (OUT), with the following parameters:
    ParameterValueDescription
    Command0x60Configure I/O pin
    I/O number0x00

    0x10

    0x20

    ...

    0x50

    IO0

    IO1

    IO2

    ...

    IO5

    I/O setting0x10Refer to the corresponding I/O setting register for the setting value
  • Read the response from Endpoint 0x84 (IN). The response can be one of the following:
    Response CodeStatusAction
    0x60Response to the I/O Set ConfigurationContinue reading
    0x20

    0x60

    0x64

    I/O is configured.

    Invalid parameters.

    Device configuration is locked.

    Retry with valid parameters.

    Unlock the device configuration and retry.

Configuring an I/O pin as a normal input pin:

  • Send the IO_SetConfiguration command through Endpoint 0x04 (OUT), with the following parameters:
    ParameterValueDescription
    Command0x60Configure I/O pin
    I/O number0x00

    0x10

    0x20

    ...

    0x50

    IO0

    IO1

    IO2

    ...

    IO5

    I/O setting0x04Refer to the corresponding I/O setting register for the setting value
  • Read the response from Endpoint 0x84 (IN). The responses can be one of the following:
    Response CodeStatusAction
    0x60Response to the I/O Set ConfigurationContinue reading
    0x20

    0x60

    0x64

    I/O is configured.

    Invalid parameters.

    Device configuration is locked.

    Retry with valid parameters.

    Unlock the device configuration and retry.

Configuring an I/O pin as an internally pulled-up input pin

  • Send the IO_SetConfiguration command through Endpoint 0x04 (OUT), with the following parameters:
    ParameterValueDescription
    Command0x60Configure I/O pin
    I/O number0x00

    0x10

    0x20

    ...

    0x50

    IO0

    IO1

    IO2

    ...

    IO5

    I/O setting0x0CRefer to the corresponding IO setting register for the setting value
  • Read the response from Endpoint 0x84 (IN). The response can be one of the following:
    Response codeStatusAction
    0x60Response to the I/O set configurationContinue reading
    0x20

    0x60

    0x64

    The I/O is configured.

    Invalid parameters.

    Device configuration is locked.

    Retry with valid parameters.

    Unlock the device configuration and retry.

Controlling a GPIO:

Setting or clearing an output pin:

  • Send the GPIO_Write command through Endpoint 0x04, OUT, with the following parameters:
    ParameterValueDescription
    Command0x64Configure I/O pin
    I/O number and output state0x00

    0x01

    0x10

    0x11

    ...

    0x50

    0x51

    IO0 Low

    IO0 High

    IO1 Low

    IO1 High

    ...

    IO5 Low

    IO5 High

  • Read the response from Endpoint 0x84 (IN). The response can be one of the following:
    Response CodeStatusAction
    0x64Response to the I/O Set ConfigurationContinue reading
    0x20

    0x60

    0x68

    The I/O is written.

    Invalid parameters.

    Pin is not configured as a GPIO output.

    Retry with valid parameters.

    Reconfigure and retry.

Reading an input pin:

  • Send the GPIO_Read command through Endpoint 0x04 (OUT), with the following parameters:
    ParameterValueDescription
    Command0x68Configure I/O pin
    The I/O number0x00

    0x10

    ...

    0x50

    IO0

    IO1

    ...

    IO5

  • Read the response from Endpoint 0x84 (IN). The response can be one of the following:
    Response CodeStatusAction
    0x68Response to the I/O set configurationContinue reading
    0x21

    0x60

    0x68

    The I/O is read.

    Invalid parameters.

    The pin is not configures as a GPIO pin.

    Retry with valid parameters.

    Reconfigure and retry.

    0x00

    0x01

    The GPIO pin is at a logical LOW level.

    GPIO pin is logical high.

    Logical state of the pin