To configure the GPIO pins of a particular port:
- Enable the clock to the port by setting the appropriate bits in the GPIO0CLKEN, GPIO1CLKEN, GPIO2CLKEN, GPIO3CLKEN, and GPIO4CLKEN registers.
- Set the direction of the GPIO port pins by programming the GPIODIR register. Writing 1 indicates output, and writing 0 indicates input.
- Configure the GPIO_PAD_CONFIG_# register to program each bit as a GPIO or other peripheral function. The GPIODMACTL register can program a GPIO pin as a µDMA trigger.
- Program the GPIOIS, GPIOIBE, GPIOEV, and GPIOIM registers to configure the type, event, and mask of the interrupts for each port.
- Perform the following steps to prevent false interrupts 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.
Use the DATA register to drive the required value on the GPIO pin (when DIR = 1) or to read a value on the GPIO pin (when DIR = 0).
Table 5-1 provides GPIO pad configuration examples, and Table 5-2 provides GPIO interrupt configuration examples.
Table 5-1 GPIO Pad Configuration Examples| Configuration | GPIO Register Bit Value |
|---|
| DIR |
|---|
| Digital Input (GPIO) | 0 |
| Digital Output (GPIO) | 1 |
Table 5-2 GPIO Interrupt Configuration Examples| Register | Desired Interrupt Event Trigger | Pin 2 Bit Value |
|---|
| 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 |