The UART module provides four I/O signals to be routed to the DIOs. The following signals are selected through the IOCFGn registers in the IOC module.
- Inputs: RXD, CTS
- Outputs: TXD, RTS
CTS and RTS lines are active low.
Note: IOC must be configured before enabling the UART to avoid unwanted transitions on the input being processed as UART signals. When IOC is configured as UART-specific I/Os (RXD, CTS, TXD, or RTS), IOC sets static output driver enable to the DIO (output driver enable = 1 for output TXD and RTS and output driver enable = 0 for inputs RXD and CTS).
To enable and initialize the UART, use the following steps:
- Enable the UART module in the CLKCTRL module by writing to the CLKCTRL.CLKENSET0[2] UART0 bit to 1. This enables the clock to UART.
- Configure the IOC module to map UART signals to the correct GPIO pins. For more information on pin connections, see Chapter 18.
This section discusses the steps required to use a UART module. For this example, the UART clock is assumed to be 48 MHz, and the desired UART configuration is the following:
- Baud rate: 115 200
- 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 BRD because the UART.IBRD and UART.FBRD registers must be written before the UART.LCRH register. The BRD can be calculated using the equation described in Section 19.3.2
Equation 7. BRD = 48 000 000 / (16 × 115 200) = 26.0416
The result of the previous equation indicates that the UART.IBRD[15:0] DIVINT bit field must be set to 26 decimal or 0x1A.
Equation 8. UART.FBRD[5:0] DIVFRAC = integer (0.0416 × 64 + 0.5) = 3
the previous equation calculates the value to be loaded into the UART.FBRD register.
With the BRD values available, the UART configuration is written to the module in the following order:
- Disable the UART by clearing the UART.CTL[0] UARTEN bit.
- Write the integer portion of the BRD to the UART.IBRD register.
- Write the fractional portion of the BRD to the UART.FBRD register.
- Write the desired serial parameters to the UART.LCRH register (in this case, a value of 0x0000 0060).
- Enable the UART by setting the UART.CTL[0] UARTEN bit.