Categories: Hardware Guide

Basics of UART

Parallel Communication vs Serial Communication

In a computer system, there are two ways in which data can be transmitted. Series and parallel. In serial communication, data is being transmitted as one bit at a time, while in parallel communication, data is being transmitted as blocks.
Since parallel communication is faster than serial communication, the internal connections in a computer are in such a way that the data transmission is made in parallel mode. But for long distance and high-frequency data transfer, the parallel mode has proved unsuitable and in such cases, a serial communication method is used. Besides, the multiple lines used in parallel mode could increase the expense of the communication process. And because of the same reasons, serial communication is used commonly in data transfer between a computer and it’s peripheral devices. Some of the peripheral modules in microcontrollers used for serial communication include USART, SPI, I2C, and USB.

Serial communications can be categorized as two, synchronous and asynchronous communications.

Synchronous Serial Transmission

In synchronous data transmission, the sender and receiver share a clock with one another. Otherwise, the sender provides a timing signal which prompts the receiver to read the next bit of the data. During data transmission, if there is no data available to transmit at a given instant, a fill character will be sent to make sure that the data is always transmitted. In printers and other fixed desk devices, data is sent on one set of wires while a clock is sent on a different set of wire.
The standard serial communications hardware in the PC does not support synchronous operations. This mode is described here for comparison purposes only.

Asynchronous Serial Transmission

In an asynchronous type of data transmission, data should be transmitted without a clock signal being sent by the sender. In general case, the sender and receiver come in agreement with the speed of transmission. To make sure the data accessing follows that agreement, both the sender and the receiver set up their own internal circuits. In order to synchronize the sending and receiving units, special bits are added to each word. A bit called ‘Start Bit’ is added to the beginning of each word that has to be transmitted. The purpose of this bit is to alert the receiver that the word of data is about to be sent. Moreover, it forces the clock in the receiver to synchronize with the clock in the transmitter. The sender and receiver clocks must be accurate enough to avoid larger frequency drift during the transmission of the remaining bits of the word.

After the ‘start bit’, the least significant bit is the one which is sent first and following it the rest of the bits are transmitted one after another. A parity bit is added by the transmitter which may be used by the receiver for error checking. After the parity bit, the transmitter sends a stop bit. after receiving all the data, the receiver checks for a parity bit. Since the parity bit is optional, the receiver and the sender must agree on whether the parity bit is to be used. After the transmission of data bits and the parity bit, the stop bit is being received. If the stop bit is not found after the data bits, the receiver identifies this as a framing error and will send a framing error signal to the host processor. this error takes place when the sender and receiver were not running at the same speed.

What is UART

A universal asynchronous receiver/transmitter (UART) is an integrated circuit that transmits data serially. To be more precise, UART is an electronic device meant for asynchronous serial transmission of data. UART consists of a separately clocked receiver and transmitter. The electric signaling levels and methods (such as differential signaling, etc.) are handled by a driver circuit external to the UART. The data format and transmission speeds are configurable in UART. UART can also be regarded as the microchip with programming that controls a computer’s interface to its attached serial devices.

UART provides the computer with RS-232 data terminal equipment interface. With the help of this, the UART can exchange data with modems and other serial devices. Besides, the RS-232 interface enables the UART to convert the bytes it receives along the parallel circuits of the computer into a single serial bit stream for outbound transmission. UART converts the serial bit stream into the bytes that the computer handles, on inbound transmission. Other functions include handling an interrupt from the keyboard and mouse, adding parity bit on outbound transmissions, checking the parity of incoming bytes and discarding the parity bit. Adding start and stop delineators on outbound and stripping them from inbound transmissions, handling interrupts from the keyboard and mouse.

UART’s parallel side is often connected to the bus of a computer. Data transmission on the serial line will be started by the UART when the computer writes a byte to the transmit data register of a UART. The universal designation indicates that the transmission speeds and data format are configurable and that the electric signaling levels and methods are typically handled by a special driver circuit that is external to the UART. USART (universal synchronous/asynchronous receiver/transmitter) is a closely related device which supports synchronous operation.

Working Principle

The transmit pin of first UART is connected to second device’s receive pin and receive pin to that of transmit pin. So data flows from transmit pin to the receive pin of the receiving UART. Since UART is an asynchronous serial transmission, it doesn’t use clocks. The data transmitted at a predetermined speed between devices called baud rate.

Baud rate

Baud rate in a data transmission refers to the number of symbols transferred per second. A symbol is a group of a fixed number of bits. The bit rate which is the number of bits transferred in a second and the baud rate becomes equal when there is only one bit in a symbol.

Data framing

UART transmits data in packets. Each data packet may contain 1 start bit, 5 to 9 data bits, an optional parity bit and 1 or 2 stop bits.

The UART receives the data from the data bus and this data are being sent by CPU, memory or microcontroller. The data transmission from the data bus to UART is in parallel mode. UART adds the start bit, parity bit and a stop bit to the data received from the data bus which creates a data packet. This data packet is serially transmitted to the receiving UART by the transmitter. The receiving pin of the receiver UART reads the data bit by bit. This data are again converted into parallel form at the receiver UART and being sent to the data bus at the receiver end after the receiver UART removes the start bit, parity bit and stop bits.

Start Bit

When there is no data transmission, the UART transmission line is held at high voltage. To initiate the data transfer, the voltage is pulled from high to low for one clock cycle. This transition acts as the start bit. And when the receiving UART detects the high to low voltage transition, it begins reading the data frame at the frequency of the baud rate.

Data frame

The data bits are usually 5 to 8 in number. If no parity bit is used, it can be 9-bit long. In general case, the least significant bit of the data is transmitted first. It is the useful data we’re actually transmitting.

Parity

A parity bit is used to indicate the change in data during transmission. There are several reasons for the change in data including mismatched baud rates, electromagnetism or long distance data transfer. After receiving the data frame, UART checks if the total number of bits in the data frame is an even or odd number. This is done by counting the number of bits with a value of 1. If the parity bit is 0, the number of bits in the data frame is an even number. If the parity bit is 1, the number of bits in the data frame is odd. If the parity bit does not match with the data, UART identifies an error in the data frame.

Stop bit

To mark the end of the data packet, the sending UART drives the data transmission line from a low voltage to a high voltage for a minimum of two-bit duration.

UART does not process the start, parity and stop bits and it automatically discards these bits, no matter the data was received correctly or not. Since the asynchronous data transmission is ‘self-synchronizing’, if no data is transmitted at a particular time, the transmission line stays idle.

Applications of UART

UARTs are commonly seen in microcontrollers. In microcontrollers, UARTs are used for specific purposes. UARTs are also found in devices such as Bluetooth modules, wireless communication, GPS units, modems and many other day-to-day applications.

Apart from RS-232, communication standards such as RS-422 and TIA also make use of UART. Generally, a UART is an individual integrated circuit used for serial communications, but there are dual UART or DUART which is a combination of two UARTs. They are usually placed in microcontrollers. Octal UART or OCTART combines two UARTs into a single chip.

Advantages

  • Most used serial standard
  • Error checking using parity bits
  • Variable data packet
  • Uses only two wires for data transmission and no clock

Disadvantages

  • UART doesn’t support multi-master multi-slave configurations
  • Data transmission speed (baud rate) should be fixed earlier, it can’t be different from others.
Share