Basics of UART Communication

Info Thread
By -
0

 UART or Universal Asynchronous Receiver Transmitter is a dedicated hardware associated with serial communication. The hardware for UART can be a circuit integrated on the microcontroller or a dedicated IC. This is contrast to SPI or I2C, which are just communication protocols.

UART is one of the most simple and most commonly used Serial Communication techniques. Today, UART is being used in many applications like GPS Receivers, Bluetooth Modules, GSM and GPRS Modems, Wireless Communication Systems, RFID based applications etc.

If you remember older computer systems, devices like Mouse, Printer and Modem are connected using a heavy connectors at the back. All these devices communicated using UART.

Even though USB has replaced all types of communication standards on computers and other devices, UART is still being used in the above mentioned applications.

Almost all microcontrollers have dedicated UART hardware built in to their architecture. The main reason for integrating the UART hardware in to microcontrollers is that it is a serial communication and requires only two wires for communication.

Before going in to further explanation of UART, how it works and steps involved in transmission and reception of data, we will try to recollect some information about Serial Communication and a small comparison between serial and parallel communications.

Brief Note on Parallel and Serial Communication

Transfer of Digital Data from one device to another can be achieved in two ways: Parallel Data Transfer and Serial Data Transfer. In parallel data transfer, all the bits are transferred from the source to destination at once.

This is possible because parallel data transfer uses multiple lanes or wires between the transmitter and receiver in order to transfer the data.

Parallel Data Transfer methods are faster and expensive as they needs more hardware and a lot of wires. Olden day’s printers are the best example for external parallel communication. Other examples are RAM, PCI, etc.

With the progress in integrated circuit technology, the digital IC’s are becoming smaller and faster and as a result the transfer rates in Parallel Communication with multiple lanes have reached a bottle neck.

Serial Communication on the hand, transfers data bit by bit using a single line or wire. For two way communication between the transmitter and receiver, we need just two wires for successful serial data transfer.

Since serial communication needs less circuitry and wires, the cost of implementing is less. As a result, using serial communication in complex circuitry might be more practical than parallel communication.


But the only concern with serial data transfers is speed. Since the data transfer occurs over a single line, the speed of transfer in serial communication is less than that of parallel communication. Now – a – days, the speed of serial data transfer isn’t a concern as advancements in technology have led to faster transfer speeds.

Introduction to UART Communication

UART or Universal Asynchronous Receiver Transmitter is a serial communication device that performs parallel – to – serial data conversion at the transmitter side and serial – to – parallel data conversion at the receiver side. It is universal because the parameters like transfer speed, data speed, etc. are configurable.

As mentioned in the introduction section, UART is a piece of hardware that acts as a bridge between the processor and the serial communication protocol or port. The following image shows this interface briefly. The serial communication can be anything like USB, RS – 232, etc.


The letter ‘A’ in UART stands for Asynchronous i.e. there is no clock signal to synchronize or validate the data transmitted from transmitter and received by the receiver (Asynchronous Serial Communication).

This is in contrast to Synchronous Serial Communication, which uses a clock signal that is shared between the transmitter and receiver in order to “Synchronize” the data between them.

If there is no clock (or any other timing signal) between the transmitter and receiver, then how does the receiver know when to read the data?

In UART, the transmitter and receiver must agree on timing parameters beforehand. Also, UART uses special bits at the beginning and ending of each data word to synchronize the transmitter and receiver. More about these special bits in the later sections.

In UART based Serial Communication, the transmitter and receiver communicate in the following manner. The UART on the sender device i.e. the transmitting UART receives parallel data from the CPU (microprocessor or microcontroller) and converts it in to serial data.

This serial data is transmitted to the UART on the receiver device i.e. receiving UART. The receiving UART, upon receiving the serial data, converts it back to parallel data and gives it to the CPU.

UART Basic Connection

The pin on the transmitting UART, which transmits the serial data is called TX and the pin on the receiving UART, which receives the serial data is called RX.

Since the UART involves parallel – to – serial and serial – to – parallel data conversion, shift registers are an essential part of the UART hardware (two shift registers to be specific: Transmitter Shift Register and Receiver Shift Register).

How UART Works?

In UART Serial Communication, the data is transmitted asynchronously i.e. there is no clock or other timing signal involved between the sender and receiver. Instead of clock signal, UART uses some special bits called Start and Stop bits.

These bits are added to the actual data packet at the beginning and end respectively. These additional bits allows the receiving UART to identify the actual data.

The image above shows a typical UART connection. The transmitting UART receives data from the controlling device through the data bus. The controlling device can be anything like a CPU of a microprocessor or a microcontroller, memory unit like a RAM or ROM, etc. The data received by the transmitting UART from the data bus is parallel data.

To this data, the UART adds Start, Parity and Stop bits in order to convert it into a data packet. The data packet is then converted from parallel to serial with the help of shift register and is transmitted bit – by – bit from the TX pin.

The receiving UART receives this serial data at the RX pin and detects the actual data by identifying the start and stop bits. Parity bit is used to check the integrity of the data.

Up on separating the start, parity and stop bits from the data packet, the data is converted to parallel data with the help of shift register. This parallel data is sent to the controller at the receiving end through a data bus.

Structure of Data Packet or Frame

The data in UART serial communication is organised in to blocks called Packets or Frames. The structure of a typical UART Data Packet or the standard framing of the data is shown in the following image.

Let us see about each piece of the frame.

Start Bit: Start bit is a synchronisation bit that is added before the actual data. Start bit marks the beginning of the data packet. Usually, an idle data line i.e. when the data transmission line is not transmitting any data, it is held at a high voltage level (1).

In order to start the data transfer, the transmitting UART pulls the data line from high voltage level to low voltage level (from 1 to 0). The receiving UART detects this change from high to low on the data line and begins reading the actual data. Usually, there is only one start bit.

Stop Bit: The Stop Bit, as the name suggests, marks the end of the data packet. It is usually two bits long but often only on bit is used. In order to end the transmission, the UART maintains the data line at high voltage (1).

Parity Bit: Parity allows the receiver to check whether the received data is correct or not. Parity is a low – level error checking system and comes in two varieties: Even Parity and Odd Parity. Parity bit is optional and it is actually not that widely used.

Data Bits: Data bits are the actual data being transmitted from sender to receiver. The length of the data frame can be anywhere between 5 and 9 (9 bits if parity is not used and only 8 bits if parity is used). Usually, the LSB is the first bit of data to be transmitted (unless otherwise specified).

Rules of UART

As mentioned earlier, there is no clock signal in UART and the transmitter and receiver must agree on some rules of serial communication for error free transfer of data. The rules include:

  • Synchronisation Bits (Start and Stop bits)
  • Parity Bit
  • Data Bits and
  • Baud Rate

We have seen about synchronisation bits, parity bit and data bits. Another important parameter is the Baud Rate.

Baud Rate: The speed at which the data is transmitted is mentioned using Baud Rate. Both the transmitting UART and Receiving UART must agree on the Baud Rate for a successful data transmission.

Baud Rate is measured in bits per second. Some of the standard baud rates are 4800 bps, 9600 bps, 19200 bps, 115200 bps etc. Out of these 9600 bps baud rate is the most commonly used one.

Let us see an example data frame where two blocks of data i.e. 00101101 and 11010011 must be transmitted. The format of the frame is 9600 8N1 i.e. 9600 bps with 8 bits of data, no parity and 1 stop bit. In this example, we haven’t used the parity bit.


Advantages of UART

  • Requires only two wires for full duplex data transmission (apart from the power lines).
  • No need for clock or any other timing signal.
  • Parity bit ensures basic error checking is integrated in to the data packet frame.

Disadvantages of UART

  • Size of the data in the frame is limited.
  • Speed for data transfer is less compared to parallel communication.
  • Transmitter and receiver must agree to the rules of transmission and appropriate baud rate must be selected.

Post a Comment

0Comments

Post a Comment (0)