16.4
Initialization and Configuration
To enable and initialize the UART, the following steps are necessary:
1.
Enable the UART module using the
RCGCUART
register (see page 388).
2.
Enable the clock to the appropriate GPIO module via the
RCGCGPIO
register (see page 382).
To find out which GPIO port to enable, refer to Table 26-5 on page 1808.
3.
Set the GPIO
AFSEL
bits for the appropriate pins (see page 770). To determine which GPIOs to
configure, see Table 26-4 on page 1797.
4.
Configure the GPIO current level and/or slew rate as specified for the mode selected (see
page 772 and page 780).
5.
Configure the
PMCn
fields in the
GPIOPCTL
register to assign the UART signals to the appropriate
pins (see page 787 and Table 26-5 on page 1808).
To use the UART, the peripheral clock must be enabled by setting the appropriate bit in the
RCGCUART
register (page 388). In addition, the clock to the appropriate GPIO module must be
enabled via the
RCGCGPIO
register (page 382) in the System Control module. To find out which
GPIO port to enable, refer to Table 26-5 on page 1808.
This section discusses the steps that are required to use a UART module. For this example, the
UART clock is assumed to be 20 MHz, and the desired UART configuration is:
■ 115200 baud rate
■ Data length of 8 bits
■ One stop bit
■ No parity
■ FIFOs disabled
■ No interrupts
The first thing to consider when programming the UART is the baud-rate divisor (BRD), because
the
UARTIBRD
and
UARTFBRD
registers must be written before the
UARTLCRH
register. Using
the equation described in “Baud-Rate Generation” on page 1165, the BRD can be calculated:
BRD = 20,000,000 / (16 * 115,200) = 10.8507
which means that the
DIVINT
field of the
UARTIBRD
register (see page 1184) should be set to 10
decimal or 0xA. The value to be loaded into the
UARTFBRD
register (see page 1185) is calculated
by the equation:
UARTFBRD[DIVFRAC] = integer(0.8507 * 64 + 0.5) = 54
With the BRD values in hand, the UART configuration is written to the module in the following order:
1.
Disable the UART by clearing the
UARTEN
bit in the
UARTCTL
register.
2.
Write the integer portion of the BRD to the
UARTIBRD
register.
3.
Write the fractional portion of the BRD to the
UARTFBRD
register.
June 18, 2014
1172
Texas Instruments-Production Data
Universal Asynchronous Receivers/Transmitters (UARTs)