17.4 Initialization and Configuration
To configure the GPIO pins of a particular port, follow these steps:
- Enable the clock to the port by setting the appropriate bits in the RCGCGPIO register, see Section 4.2.87. In addition, the SCGCGPIO and DCGCGPIO registers can be programmed in the same manner to enable clocking in Sleep and Deep-Sleep modes.
- Set the direction of the GPIO port pins by programming the GPIODIR register. A write of a 1 indicates output and a write of a 0 indicates input.
- Configure the GPIOAFSEL register to program each bit as a GPIO or alternate pin. If an alternate pin is chosen for a bit, then the PMCx field must be programmed in the GPIOPCTL register for the specific peripheral required. There are also two registers, GPIOADCCTL and GPIODMACTL, which can be used to program a GPIO pin as a ADC or μDMA trigger, respectively.
- Set the EDMn field in the GPIOPC register as shown in Table 17-1.
- Set or clear the GPIODR4R register bits as shown in Table 17-1.
- Set or clear the GPIODR8R register bits as shown in Table 17-1.
- Set or clear the GPIODR12R register bits as shown in Table 17-1.
- Program each pad in the port to have either pullup, pulldown, or open drain functionality through the GPIOPUR, GPIOPDR, or GPIOODR register. Slew rate may also be programmed, if needed, through the GPIOSLR register.
- To enable GPIO pins as digital I/Os, set the appropriate DEN bit in the GPIODEN register. To enable GPIO pins to their analog function (if available), set the GPIOAMSEL bit in the GPIOAMSEL register.
- Program the GPIOIS, GPIOIBE, GPIOEV, and GPIOIM registers to configure the type, event, and mask of the interrupts for each port.
NOTE
To prevent false interrupts, the following steps should be taken when reconfiguring GPIO edge and interrupt sense registers:
- Mask the corresponding port by clearing the IME field in the GPIOIM register.
- Configure the IS field in the GPIOIS register and the IBE field in the GPIOIBE register.
- Clear the GPIORIS register.
- Unmask the port by setting the IME field in the GPIOIM register.
- Optionally, software 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.
When the internal POR signal is asserted and until otherwise configured, all GPIO pins are configured to be undriven (tristate): GPIOAFSEL = 0, GPIODEN = 0, GPIOPDR = 0, and GPIOPUR = 0Table 17-2 shows all possible configurations of the GPIO pads and the control register settings required to achieve them. Table 17-3 shows how a rising edge interrupt is configured for pin 2 of a GPIO port.
Table 17-2 GPIO Pad Configuration Examples
| Configuration |
GPIO Register Bit Value (1) |
| AFSEL |
DIR |
ODR |
DEN |
PUR |
PDR |
DR2R |
DR4R |
DR8R |
DR12R |
SLR |
| Digital Input (GPIO) |
0 |
0 |
0 |
1 |
? |
? |
X |
X |
X |
X |
X |
| Digital Output (GPIO) |
0 |
1 |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
| Open Drain Output (GPIO) |
0 |
1 |
1 |
1 |
X |
X |
? |
? |
? |
? |
? |
| Open Drain Input/Output (I2CSDA) |
1 |
X |
1 |
1 |
X |
X |
? |
? |
? |
? |
? |
| Digital Input/Output (I2CSCL) |
1 |
X |
0 |
1 |
X |
X |
? |
? |
? |
? |
? |
| Digital Input (Timer CCP) |
1 |
X |
0 |
1 |
? |
? |
X |
X |
X |
X |
X |
| Digital Input (QEI) |
1 |
X |
0 |
1 |
? |
? |
X |
X |
X |
X |
X |
| Digital Output (PWM) |
1 |
X |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
| Digital Output (Timer PWM) |
1 |
X |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
| Digital Input/Output (SSI) |
1 |
X |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
| Digital Input/Output (UART) |
1 |
X |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
| Analog Input (Comparator) |
0 |
0 |
0 |
0 |
0 |
0 |
X |
X |
X |
X |
X |
| Digital Output (Comparator) |
1 |
X |
0 |
1 |
? |
? |
? |
? |
? |
? |
? |
(1) X = Ignored (don’t care bit)
? = Can be either 0 or 1, depending on the configuration
Table 17-3 GPIO Interrupt Configuration Example
| Register |
Desired Interrupt Event Trigger |
Pin 2 Bit Value (1) |
| 7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
| GPIOIS |
0 = edge
1 = level |
X |
X |
X |
X |
X |
0 |
X |
X |
| GPIOIBE |
0 = single edge
1 = both edges |
X |
X |
X |
X |
X |
0 |
X |
X |
| GPIOIEV |
0 = Low level, or falling edge
1 = High level, or rising edge |
X |
X |
X |
X |
X |
1 |
X |
X |
| GPIOIM |
0 = masked
1 = not masked |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
(1) X = Ignored (don’t care bit)