UART Communication Introduction, Working, Frame Format, Applications (original) (raw)

UART Communication stands for Universal asynchronous receiver-transmitter. It is a dedicated hardware device that performs asynchronous serial communication. It provides features for the configuration of data format and transmission speeds at different baud rates. A driver circuit handles electric signaling levels between two circuits. A Universal asynchronous receiver-transmitter (UART) Communication is usually an individual component or part of an integrated circuit. We can use it for communications over a computer or its peripheral devices such as a mouse, monitor or printer. In microcontroller chips, there are usually a number of dedicated UART hardware peripherals available.

Universal Asynchronous Receive Transmit (UART) or Serial communication is one of the most simple communication protocols between two devices. It transfers data between devices by connecting two wires between the devices, one is the transmission line while the other is the receiving line. The data transfers bit by bit digitally in form of bits from one device to another. The main advantage of this communication protocol is that its not necessary for both the devices to have the same operating frequency. For example, two microcontrollers operating at different clock frequencies can communicate with each other easily via serial communication. However, a predefined bit rate that is referred to as baud rate usually set in the flash memory of both microcontrollers for the instruction to be understood by both the devices.

Transmitting and receiving serial data

The transmitting UART takes bytes of data and transmits the bits in a sequential form. The second transmitter which is the receiver reassembles the bits into a complete byte. Serial transmission of data through a single wire is actually more cost-effective than parallel transmission through multiple wires.

Communication between two UART devices may be simplex, full-duplex or half-duplex. Simplex communication is a one-direction type of communication where the signal moves from one UART to another. It doesn’t have provision for the receiving UART to send back signals. A full-duplex is when both devices can transmit and receive communications at the same time. A half-duplex is when devices take turns to transmit and receive.

Structure of a UART Protocol

UART technology

There was a time not so long ago when keyboards, mice, and printers had thick cables and clunky connectors. These had to be literally screwed into the computer. These devices where using UART to communicate with computers. Although these clunky cables have been replaced with USB, you can still find UARTs being used in DIY electronics such as Raspberry Pi, Arduino, and other common microcontrollers. We can use it to connect Bluetooth modules and GPS modules.

UART has a different transfer protocol than other communication protocols such as SPI and I2C. It is a physical circuit fount in a microcontroller. It can also function as a stand-alone integrated circuit. One significant advantage of UART is that it only relies on two wires to transmit data.

How two Device Communicate through UART

UART BUS between two devices

It takes two UART’s to communicate directly with each other. On one end the transmitting UART converts parallel data from a CPU into serial form then transmits the data in serial form to the second UART which will receive the serial data and convert it back into parallel data. This data can then be accessed from the receiving device.

Instead of cloak signals the transmitting and receiving bit use start and stop bit signals for the data packages. These start and stop bits define the beginning and the end of the data packages. Therefore the receiving UART knows when to start and stop reading the bits.

The Receiving UART will detect the start bit then start reading the bits. The specific frequency used to read the incoming bits is known as the baud rate. The baud rate is a measure used for the speed of data transfer. The unit used for baud rate is bits per second (bps). In order for the data transfer to be a success both the transmitting and receiving UART must operate at almost the same baud rate. However, if the baud rates differ between both UARTs they must only differ by 10%. The receiving and transmitting UART must be configured to receive the same data packages.

How UART communication works

UART communication frame

Now let us discuss the transmission of data through UART in a step by step manner.

UART data transmission 1

UART data transmission 2

Bit by bit the data packet is serially output at the Tx pin. UART will then read the data packet bit by bit through its Rx pin

UART data transmission 3

UART data transmission 4

Explanation of Timing Diagram

This is how UART transmitted data is organized: It is organized into packets that have one start bit, 5 to 9 data bits. A parity bit is optional, and 2 stop bits.

Baud Rate

The communication between two devices via UART Protocol occurs by transmission of bits. A total of 8 bits are sent one right after the other to transmit a byte. A bit is either a logical low or high. The time interval between two bits is called the baud rate or bit rate. it must be defined in both devices so the sending device can encode the data into bits with this specific time interval and the receiver expects the successive bits at the right time. The most commonly used baud rates is 9600 bits per second. Although other baud rates are also used, but the higher the bit rate, the more chances there are of data corruption. Lower bit rates are used when there is greater physical distance between two devices because the length of the wire increases resistance and thus deteriorates the signal.

Timing Diagram of UART

The data in Serial communication is sent by transmitting data packets. Each data packet consists of starting bit, data byte (8 bits), a parity bit (sometimes optional) and a stop bit.

Timing diagram Working

Errors in UART

Conclusion

Let’s summarize the steps of UART communication:

UART Communication modules

A UART that combines two UARTs into a single chip is known as a dual UART or DUART. A quadruple UART combines four UARTs in a single chip. If a UART combines eight UARTs into one chip it is called an OCTART or octal UART. The most common OCTART is the Exar XR16L788.

Applications of UART

Pros of UART

Although there are no perfect communication protocols that are perfect, UARTs are good at transmitting and receiving data.

Disadvantages of UART

UART Serial Programming in Arduino

Arduino has the capability to communicate with other devices via UART Protocol. This can be used when connecting one Arduino to another or when connecting an Arduino to a UART compatible module like HC-05 Bluetooth module. To achieve serial communication, follow the following steps:

UART Transmitter Code for Arduino

As discussed above, when we have to transmit data via serial port, we encode it into data packets. Thankfully, there is a built in Arduino library that does it for us. Lets make an example code that will send a simple “Hello World” to the receiver.

The basic code looks like this

void setup()

{

  Serial.begin(9600); //Initialize the serial port

}

void loop()

{

  Serial.println("Hello World"); //transmit the string to receiver Arduino

  delay(100); //Wait for 10 milli sec before transmitting it again because we are in the loop() function

}

UART Receiver Code for Arduino

To receive the string transmitted by the transmitter Arduino, we

The code goes like this

void setup()

{

  Serial.begin(9600);

}

void loop()

{

if (Serial.available()) //If the data is transmitted from the transmitter Arduino, only then the contents of if function will be executed

  {

      Serial.print(Serial.read()); //Print the received byte to the serial monitor.

  }

}

The serial monitor will display

Software Serial UART for Arduino

Arduino has dedicated Tx and Rx pins and it can communicate to only one device at a time via these pins. But what if we want to communicate to multiple devices via Serial Protocol. Well, we can do that by creating a software serial in which any of the digital pins of Arduino can transmit and receive data via Serial protocol.

Software UART Library

To achieve this, the following steps are taken

The code goes like this

#include <SoftwareSerial.h> //Include Software serial library

SoftwareSerial newserial(2, 3); //Initialize the object newserial and set pin 2 as Rx and 3 as Tx

void setup()

{

  newserial.begin(9600); //Set baud rate of software serial at 9600bps

}

void loop()

{

  newserial.println("Hello World"); //Print the received byte to the serial monitor.

}

If we run the same code on receiver Arduino that we ran before, we would get the same output.

Other Serial communication Protocols:

Practical Tutorials and Projects

The following articles contains examples of UART Serial communication use: