UART
What is UART? What does it stand for?
UART, which stands for Universal Asynchronous Receiver or Transmitter, is a protocol device that is used for exchanging data between devices. UART is one of the most commonly used hardware communication protocols used in embedded systems.
How does it work? How are UART connections made?
An external device, such as a CPU or microcontroller, transfers the data to the UART through the data bus. The UART device turns the data from the data bus into a data packet by adding a start bit, a parity bit, and a stop bit.
This data packet is transferred via serial communication through the transmitting pin (Tx). This means that the data is streamed one bit at a time, which is why UART communication can be established using only 2 wires. The receiver on the other UART reads the serial data and converts the packet back into parallel data using the same process (removing start bit, parity bit, and stop bits). This data is then sent to its data bus.
The start bit is generally configured to be low voltage (0) as the transmission line is typically high voltage (1) when data is not being transferred. The receiver begins reading once it detects the change in voltage from high to low and stops reading at the stop bit, which changes the voltage back to high (1).
How many wires does it have?
UART uses only two wires for receiving and transmitting signals. One from device A’s transmitter to device B’s receiver, and vice versa. Note: connections to GND are also needed for both devices of interest.
What is baud rate? What is the rule of thumb regarding baud rates for two devices communicating via UART?
Baud rate is the rate at which data is transferred, in bits per second (bps).
In general, both UART devices should be operating at around the same baud rate. differing by a maximum of 10%. Furthermore, they both must be configured to transmit and receive the same data packet bit stream.
What are some standard communication rates?
The standard communication rate is around 9600 baud. Other common rates (in baud) include: 19200, 38400, 57600, 115200, etc.
How many devices can talk to each other? What is the direction of communication?
The direction of communication is from the transmitter to the receiver, and generally, one device with a transmitter can talk to one other device with a receiver. However, communication with multiple devices using one UART can also be established using MCUs with many hardware UART modules.
Communication between devices can be simplex (one directional transmission), half-duplex (transmission in both directions), or duplex (simultaneous transmission in both directions).
Is it synchronous or asynchronous?
As the name suggests, UART is an asynchronous protocol, so the operation executes independently of others. This means that instead of clock signals, it adds start and stop bits to synchronize the output of bits from the transmitter (uses bit stream data).
What is USART?
USART (Universal Synchronous/Asynchronous Receiver/Transmitter) is a protocol that also uses serial bit streams to transfer data rather than clock signals.
It is similar to UART, but there are some key differences:
USART can run in synchronous mode, which means that the transmitter will generate a clock that the receiver on another device can identify without having to be configured to align with the baud rate. The synchronous mode allows USART to transfer data faster than UART.
USART can support more standard communication protocols compared to UART (IrDA, LIN, etc.)
Note, in synchronous mode, the data must be transferred in blocks and at a fixed rate. Additionally, connections must respond before sending new data.
Essentially, USARTs hold the same functionalities as UARTs, with some additional capabilities for handling synchronously. They can often be used simply as UARTs.
How is data read if there is no clock?
Data is read and transferred serially as data packets. It converts data from a data bus into a bit stream (start bit to stop bit) and transfers it serially bit by bit. The receiver reads the bit stream serially as well.
Does UART have an error checking? If so, what form does it take?
UART adds parity bits to the stream to help detect whether errors have occurred while the data was being transferred. These changes in data can be products of electromagnetic radiation, differing baud rates, or a long transmission line.
Analysis of the parity bit requires a sum of all the data bits. An even parity bit is represented by 0 while an odd parity bit is represented by a 1. If the UART receiver identifies an odd number of bits in the data frame and the parity bit is set to be even, the receiver knows the bits in the data have changed. If the number of bits in the data frame matches what the parity bit suggests, it indicates that the transmission was successful.
What is oversampling? How is it implemented? Why is it needed? What are some common oversample rates for UART?
Oversampling is a scheme used by the receiver of a UART or USART in asynchronous mode for retrieving data bits in a stable manner.
The receiver of a UART is always reading from the wire it is connected to, it only knows to start and stop reading in the bit stream based on the shift from high to low voltage and vice versa by the start and stop bits, respectively. The rate at which the receiver reads is called sampling. Oversampling rate is the rate the receiver needs to get to to be able to read in each data bit at a stable level. It enables the receiver to accurately identify when the data bits are being read in.
The oversampling scheme is implemented with the use of a tick counter or timer with the receiver. When the counter reaches the middle of the oversampling rate, the bit can be shifted in the register, while the counter clears and restarts. This is done so the receiver can align itself as close as possible to the center point of each data bit, which ensures there is more data stability when the bit is read and less deviation.
The most popular oversampling rate is 16 times the baud rate. 8 times the baud rate is also a commonly accepted oversampling rate in the industry.
When would I use UART over SPI or I2C?
Although each of these protocols have their own advantages and disadvantages, one of the primary benefits of using UART is that the devices only require 2 wires to communicate. Furthermore, data can be sent asynchronously over long ranges. An ideal use case for UART would be situations where data needs to be transferred directly to one device (unless using MCUs with multiple UART modules) over a longer range. It is important to keep in mind that the data being transferred with UART devices must be less than 9 bits and will generally transfer at a slower rate.
Information in this section was retrieved from the following links:
https://robo-tronix.weebly.com/uploads/2/3/2/1/23219916/uart_design_doc.pdf
UART vs I2C vs SPI – Communication Protocols and Uses - Latest Open Tech From Seeed