What is UART? simple and easy explanation – IOT 8

What is UART?

Universal Asynchronous Receiver/Transmitter (UART) is a hardware device developed for transmitting and receiving data asynchronously.

Unlike SPI and I2C this is not a communication protocol rather it is a physical circuit. Here data format and transmission speeds are configurable.

UART Connections

It transmits data in serial format. It has only 2 pins/terminals/ports, one for transmitting and another one for receiving. Transmitting pin is denoted by Tx and the receiving pin is denoted by Rx.

Two UART devices communicate directly with each other, first’s device’s Tx is connected with second’s Rx and vice versa, as shown in figure below.

uart-connections-itvoyagers

It receives data from a controlling device like processor or it revives data from peripherals in parallel format.

It converts this data into serial format and transmits it to the next UART device which again converts received data to parallel format and sends it further, as shown in diagram below.

As the name says it is asynchronous hence there is no clock signal, instead it uses start and stop bit at the starting and ending of data packet respectively. These bits help receiving UART device to understand when to start reading data packets and when to stop. 

It is important to maintain baud rate. Baud rate is nothing but the number of bits transferred in one second its unit is bps. The baud rates of each UART must be within 10% of each other.

Note : In raspberry pi GPIO14 and GPIO15 are Tx and Rx port respectively.

Working of UART

Peripherals which use UART for transmission send their data in parallel form. E.g. If a microcontroller wants to send data to another peripheral through UART then first it will send data to the UART device in parallel format.
UART device collect all data and convert it into a serial format and add start bit, parity bit and stop bit this will create a complete data packet.

working-of-uart-itvoyagers

Transmitter (Tx) sends this data packet to the receiver (Rx). Receiving UART device accepts this data packet and removes all extra bits like start bit, parity bit and stop bit. Then it converts the received serial data packet in parallel format and sends it further to the targeted peripheral.

Data packets’s bits

uart-packet-format-itvoyagers

Start Bit

Ideal state of UART data transmission line (Tx) is logical high (which means there is high pulse). When sender UART wants to start transmission then it sets Tx line to low (which means it sends low pulse to receiver Rx) which indicates that transmission is going to start.
Receiving UART receives low signal/pulse and gets ready to accept data from the transmitter.

Data Frame

This portion contains actual data which is to be transferred. Length of data frame varies from 5 to 8 bits when parity bit is included and when parity bit is not set or absent then length of data frame can go upto 9 bits. Most of the time LSB (Least Significant Bit) is transmitted first.

Parity Bit

It is a single bit field which allows the receiver to check whether the received data is correct or not. This is an optional bit. It has two types Odd parity and Even parity. It is added as LSB in original data.
Odd parity : Total number of 1’s i.e high bits are odd in the data frame then parity bit is set to 0 which indicates odd parity.
Even parity : Total number of 1’s i.e high bits are even in the data frame then parity bit is set to 1 which indicates even parity.

Stop Bit

This bit indicates the end of the data packet. Transmitter sets the Tx (Transmission line) line in ideal state i.e. in high state (High pulse) to indicate end of transmission.

Advantages of UART

  • It’s bidirectional.
  • It’s a full duplex.
  • Since it is asynchronous there is no clock signal.
  • Error checking using parity bit.
  • Data format and transmission speeds are configurable.
  • As long as both sides are set up for it, the structure of the data packet can be changed.

Disadvantages of UART

  • Length of the data packet is limited to 9 bits maximum.
  • The baud rates of each UART must be within 10% of each other.
  • There are no multiple senders or receivers, in other words it does not support multiple masters or slaves.

References

Other related IOT topics

We are aiming to explain all topics and concepts of IOT in easiest term as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment