UART Drivers

UART Basics and Best Practices

The UART module is abstraction module that caters to instances of the Universal Synchronous and Asynchronous Receiver and Transmitter USART) modules that is present in PIC and AVR devices. The USART is used to transfer data from one device to the other. A USART is able to transmit a byte stream on an I/O pin (the TX pin), and receive a byte stream on another I/O pin (the RX pin). The rate at which bits are shifted out on the I/O pins is called the baud rate. The baud rate can be selected by the user, and configured in MCC and START.

In general, the USART can operate in:

  • Asynchronous mode (UART). The receiver uses the baud rate setting to recover the individual bits.
  • Synchronous mode (USART). The transmitter uses an additional I/O pin, the XCK pin, to transmit a bit clock. The receiver uses the XCK info to sample the incoming bits.

The USARTs are able to generate interrupts when a byte has been transmitter or received. A USART driver can therefore either be:

  • Polled: The driver must poll the USARTs status register to detect when a byte has been received or transmitted. Based on the result of the polling, the driver will write the next byte to be transmitted (TX data) or read the received byte (RX data) from the USART.
  • Interrupt-driven: The USART issues an interrupt when a byte has been received or transmitted. The driver's Interrupt Service Routine (ISR) will write TX the next data or read RX data from the USART. The RX and TX data are typically placed in circular buffers (ringbuffers).

Some devices may have DMA controllers. In such devices, the USART may also have a DMA-driven driver.