1.12.11 General Purpose I/O (GPIO)

General purpose I/O pins are the simplest of peripherals. They allow the PIC32MZ EF family device to monitor and control other devices. To add flexibility and functionality, some pins are multiplexed with alternate function(s). These functions depend on which peripheral features are on the device. In general, when a peripheral is functioning, that pin may not be used as a general purpose I/O pin.

Some of the key features of the I/O ports are:

  • Individual output pin open-drain enable/disable

  • Individual input pin weak pull-up and pull-down

  • Monitor selective inputs and generate interrupt when change in pin state is detected

  • Operation during Sleep and Idle modes

  • Fast bit manipulation using CLR, SET and INV registers

Using The Library

The GPIO peripheral library provides two kinds of functions which can be used to control GPIO Pins:

  1. Pin Functions.

  2. Port Functions.

Pin functions take a particular pin as input and operates only on that pin without affecting any other pins. Whereas port functions can operate on multiple pins of the same port together.

The GPIO peripheral library can generate a callback on a pin interrupt if the pin interrupt is enabled in the MHC.

Library Interface

General Purpose I/O peripheral library provides the following interfaces:

Functions

Name Description
GPIO_Initialize Initialize the GPIO library
GPIO_PortRead Read all the I/O lines of the selected port port
GPIO_PortWrite Write the value on the masked I/O lines of the selected port
GPIO_PortLatchRead Read the latched value on all the I/O lines of the selected port
GPIO_PortSet Set the selected IO pins of a port
GPIO_PortClear Clear the selected IO pins of a port
GPIO_PortToggle Toggles the selected IO pins of a port
GPIO_PortInputEnable Enables selected IO pins of a port as input
GPIO_PortOutputEnable Enables selected IO pins of a port as output(s)
GPIO_PortInterruptEnable Enables IO interrupt on selected IO pins of a port
GPIO_PortInterruptDisable Disables IO interrupt on selected IO pins of a port
GPIO_PinWrite Writes the selected pin
GPIO_PinRead Read the selected pin value
GPIO_PinLatchRead Read the value driven on the selected pin
GPIO_PinToggle Toggles the selected pin
GPIO_PinSet Sets the selected pin
GPIO_PinClear Clears the selected pin
GPIO_PinInputEnable Enables selected IO pin as input
GPIO_PinOutputEnable Enables selected IO pin as output
GPIO_PinInterruptEnable Enables IO interrupt on selected IO pin
GPIO_PinInterruptDisable Disables IO interrupt on selected IO pin
GPIO_PinIntEnable Enables IO interrupt on selected IO pin
GPIO_PinIntDisable Disables IO interrupt on selected IO pin
GPIO_PinInterruptCallbackRegister Allows application to register callback for every pin

Data types and constants

Name Type Description
GPIO_PORT Enum Identifies the available GPIO Ports
GPIO_PIN Enum Identifies the available GPIO port pins
GPIO_INTERRUPT_STYLE Enum Identifies different GPIO interrupt types
GPIO_PIN_CALLBACK Typedef Pointer to a GPIO Pin-Event handler function