Serial Communications Protocols - Part Two: UART
In this article, we will be looking at the popular UART device. It’s not a communication protocol but rather the physical circuit used in microcontrollers or stand-alone ICs to transmit and receive serial data. It supports the series of articles we’ve produced to look at some of the different types of Serial Communication Protocols available.
Serial communications are the perfect mechanism for transmitting information between devices such as microcontrollers, data-producing peripherals, and other smart devices. We hope you will find this resource invaluable next time your design needs to incorporate a serial communication bus. The UART is commonly also referred to as the Serial Port on a device. However, this can often be confused with another kind of serial port, which uses the DB9 style connector and uses RS-232 as a hardware protocol. It is not uncommon to have a UART connected to an RS-232 transceiver for a UART peripheral on a microcontroller and an RS-232 based device to communicate with each other.
UART stands for Universal Asynchronous Receiver Transmitter. This communication system requires two pins, except for the ground. One is labeled TX, the transmitter, and the other labeled RX, the receiver. The appearance of the word asynchronous in the name means that it does not require a clock signal. As it does not have a clock, the transmitting and the receiving devices must use the same baud rate.
Baud rate (Bd) is a unit of measurement of the transmission rate. This parameter determines the communication speed over the data channel of the transmitter and receiver. Baud rate can be represented as bits per second to make it simpler. So, a rate of 1000 Bd means that the communication speed is 1000 bits per second, or the duration of one bit is 1/1000 second or 1 millisecond. Baud rates have standard metric prefixes such as kBd (kilobaud), MBd (megabaud), or GBd (Gigabaud). The baud rate includes non-data parts of a message such as a start and stop bits, which means that the transmission rate of useful information sent from the transmitter to the receiver will be slightly less.
Some of the more popular predefined UART baud rates include:
- 110 Baud
- 300 Baud
- 1200 Baud
- 4800 Baud
- 9600 Baud
- 19200 Baud
- 38400 Baud
- 115200 Baud
Sometimes, both communicating devices’ baud rate can be adjusted, while sometimes, one of the devices will have a fixed baud rate requiring that the other one change match it.
So, to connect the two devices using the UARTs, the transmitter TX pin should be connected to the receiver RX pin:
Basic UART wiring with TX, RX, and ground
You will have RX and TX pins on both devices in some configurations, allowing you to send commands from a microcontroller to a dedicated IC and receive orders or information back in the other direction. That is called a duplex connection. There are also applications when feedback from the second device is not required. Hence, communications are only necessary for one direction; therefore, only one TX to RX transmission line is needed. This is called a simplex connection.
The transmitting device will need to send a start bit to initiate the communications from that device to the receiving device. This bit informs the receiving device that the communications have started.
UART device sends a start bit (beginning communications)
The data bits are then sent as an eight-bit stream, representing the real data, where the most significant bit (MSB) is labeled D7, and the least essential bit (LSB) is labeled D0.
The first device in UART communication sends data bits after the first start bit.
And at the end of these data bits, the transmitter then sends a stop bit, which indicates that this is the end of the message, and places the UART bus into its idle mode.
The first device in UART communication sends a stop bit after the data bits.
We can see in this case; the complete UART message will consist of 10 bits. In the idle mode, the UART bus is pulled high, it sends a start bit which is low, and after that comes 8 data bits, then followed by the stop bit. The stop bit is not limited to being just one bit; it can come in various configurations, depending on how fast the communication rate is. This configuration means that the entire message bit set constantly changes the bus signal voltage level from low to high at least once:
Example of UART serial communication package
The most significant bit D7 may also be used as a Parity bit. This bit provides a rudimentary error checking mechanism that appears in the smallest blocks of the communications. The parity bit can be used to ensure that the total number of high bits or ones are either odd or even, depending on the coding. For an even parity check, if data bits D0 to D6 are set, they consist of an even number of high bits, then the parity bit is set to 0 (low). Conversely, if this set of bits has an uneven number of high bits, then the parity bit is set to 1 (high). This ensures that the total number of high bits in the message will be even. In case of an uneven parity check, then if data bits D0 to D6 are set such that they consist of an even number of high bits, the parity bit is set to 1 (high). Conversely, if this set of bits has an uneven number of high bits, then the parity bit is set to 0 (low). This ensures that the total number of high bits in the message will be odd.
So, by using the parity bit, errors may be detected by checking the set bits. Suppose the total number of bits, including the parity bit, set high is incorrect. In that case, the parity bit has allowed the receiver to detect an error during transmission. However, this type of error protection cannot correct the mistake, only to catch that one has occurred as there is no way to determine which bit in the overall bit set is incorrect. It can only detect if one bit is in the wrong state; any errors that affect multiple bits may not be detected if the overall parity ends up being correct.
If the parity error is detected, then the whole message must be discarded and re-transmitted from scratch. In the event of high interference or noise levels, it could take a significant time to achieve a successful transmission; however, it helps prevent message errors.
In addition to that, the receiving and transmitting side of the UART communications must use precisely the same baud rate and character length, parity mechanism, and stop bit configuration for successful communications.
There is also a variant of the UART, which is called a USART. This is a Universal Synchronous Asynchronous Receiver Transmitter. It can act as both an asynchronous channel (just like the UART) and a synchronous channel when the data is clocked. The clock can be recovered from the data itself or sent as a separate external signal.
When using a USART in its synchronous mode, no start and stop bits are required. This allows communications to use a higher data rate when operating synchronously because the bit timings have the clock reference. Therefore, more bits can be used for data instead of being used for the start/stop bits.
USART communication example
UART |
USART |
The UART requires only a data signal |
The USART synchronous mode requires both data and a clock. |
In the UART, the data does not have to be transmitted at a fixed rate. |
In the USART synchronous mode, the data is transmitted at a fixed rate. |
In the UART, data is customarily transmitted one byte at a time. |
In the USART, synchronous data is typically transmitted in the form of blocks of data. |
In the UART, the data transfer speed is set around specific values such as 4800, 9600, 38400 bps, etc. |
In the USART, the synchronous mode allows for a higher DTR (data transfer rate) than for the asynchronous mode if all other factors are held constant. |
UART speed is limited to around 115200 bps. |
USART can achieve rates faster than 115 kbps. |
Full-duplex communications: data can be sent in both directions simultaneously. |
Half-duplex communications: data can only be sent in one direction at a time. |
The primary purpose of the UART and USART is to convert the parallel data on PC bus lines to serial data that can be transmitted using line drivers over a bus that conforms to a serial communications protocol standard such as RS-232 or RS-485. A converter will be required to interface between the UART/USART and the external bus. This then allows that data to be read by a similar device without the two needed to use precisely the same serial data format. As long as the transmission between the two is to a common supported standard protocol, the implementation of the serial communications within each device can be specific to that device.
While UART has largely been superseded by USB in the computer market, they are still widely used for serial communications in low-cost devices.
Summary
This article has looked at some of the popular UART device features and discussed some of its advantages and implementation details. In the next article, Serial Communications Protocols - Part Three: RS-232, we will look at some of the serial communication protocols available. Did you miss something? Check out the introduction to Serial Communication Protocols.
The design tools in Altium Designer® contain everything you need to keep up with new technology. Talk to us today and find out how we can enhance your next PCB Design.