3.13.10 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 MCC.

Library Interface

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

Functions

NameDescription
GPIO_InitializeInitialize the GPIO library
GPIO_PortReadRead all the I/O lines of the selected port port
GPIO_PortWriteWrite the value on the masked I/O lines of the selected port
GPIO_PortLatchReadRead the latched value on all the I/O lines of the selected port
GPIO_PortSetSet the selected IO pins of a port
GPIO_PortClearClear the selected IO pins of a port
GPIO_PortToggleToggles the selected IO pins of a port
GPIO_PortInputEnableEnables selected IO pins of a port as input
GPIO_PortOutputEnableEnables selected IO pins of a port as output(s)
GPIO_PortInterruptEnableEnables IO interrupt on selected IO pins of a port
GPIO_PortInterruptDisableDisables IO interrupt on selected IO pins of a port
GPIO_PinWriteWrites the selected pin
GPIO_PinReadRead the selected pin value
GPIO_PinLatchReadRead the value driven on the selected pin
GPIO_PinToggleToggles the selected pin
GPIO_PinSetSets the selected pin
GPIO_PinClearClears the selected pin
GPIO_PinInputEnableEnables selected IO pin as input
GPIO_PinOutputEnableEnables selected IO pin as output
GPIO_PinInterruptEnableEnables IO interrupt on selected IO pin
GPIO_PinInterruptDisableDisables IO interrupt on selected IO pin
GPIO_PinIntEnableEnables IO interrupt on selected IO pin
GPIO_PinIntDisableDisables IO interrupt on selected IO pin
GPIO_PinInterruptCallbackRegisterAllows application to register callback for every pin

Data types and constants

NameTypeDescription
GPIO_PORTEnumIdentifies the available GPIO Ports
GPIO_PINEnumIdentifies the available GPIO port pins
GPIO_INTERRUPT_STYLEEnumIdentifies different GPIO interrupt types
GPIO_PIN_CALLBACKTypedefPointer to a GPIO Pin-Event handler function