GPIO Initialization and Configuration
The GPIO modules may be accessed via two different memory apertures. The legacy aperture, the Advanced Peripheral Bus (APB), is backwards-compatible with previous devices. The other aperture, the Advanced High-Performance Bus (AHB), offers the same register map but provides better back-to-back access performance than the APB bus. These apertures are mutually exclusive. The aperture enabled for a given GPIO port is controlled by the appropriate bit in the GPIOHBCTL register.
To configure the GPIO pins of a particular port, follow these steps:
- Set up the system clock
- Set up the system clock for the specific GPIO Port to enable the clock to drive the port by setting the appropriate bits in the GPIO Run Mode Clock Gating Control (RCGCG2) Register. More …
- Unlock the port
- After enabling the clock some ports are still locked. This step is only needed for pins PC0-3, PD7 and PF0 on TM4C123GXL LaunchPad. More …
- Disable Analog function
- Disable the analog function of the pin in the Analog Mode Select register (AMSEL) More …
- Configure each bit as a GPIO Mode or Alternate Mode
- Optionally you can configure the GPIOAFSEL register to program each bit as a GPIO Mode or Alternate Mode. More …
- Set up the direction for each pin on the GPIO
- Set up the direction for each pin on the GPIO port by programming the GPIODIR register. More …
- Enable GPIO pins as digital I/Os
- To enable GPIO pins as digital I/Os, set the appropriate DEN bit in the GPIODEN register. More …
- Setup the drive strength for each pin
- Optionally, you can setup the drive strength for each pin through the GPIODR2R, GPIODR4R, or GPIODR8R registers. More …
- Configure each pad in the port to have pull-up, pull-down, or open drain function
- Optionally, you can configure each pad in the port to have pull-up, pull-down, or open drain function through the GPIOPUR, GPIOPDR , or GPIOODR register. More …
- Set up the type, event, and mask of the interrupts for each port
- Optionally, you can configure the GPIOIS, GPIOIBE, GPIOEV, and GPIOIM registers to set up the type, event, and mask of the interrupts for each port if interrupts are used for the port. More …
- Lock the configurations of the NMI and JTAG/SWD pins on the GPIO port
- Optionally, you can lock the configurations of the NMI and JTAG/SWD pins on the GPIO port pins by setting the LOCK bits in the GPIOLOCK register. More …
- Read/Write Data Register
- The GPIODATA register is the data register. More …
Recent Comments