UART Communication Protocol - How it works? - Codrey Electronics (2024)

UART (Universal Asynchronous Transmitter Receiver), this is the most common protocol used for full-duplex serial communication. It is a single LSI (large-scale integration) chip designed to perform asynchronous communication. This device sends and receives data from one system to another system.

In this tutorial, you will learn the basics of UART communication, and the working of the UART.

Contents hide

1 What is UART?

2 Why UART is used?

3 Block Diagram

4 How UART works?

5 Protocol Format

5.1 Transmission

5.2 Reception

6 Example of UART interfacing

7 ESP8266 Commands

8 UART vs USART

9 RS232 Voltage Levels

10 Applications

What is UART?

“UART” stands for Universal Asynchronous receiver-transmitter. It is a hardware peripheral that is present inside a microcontroller. The function of UART is to convert the incoming and outgoing data into the serial binary stream. An 8-bit serial data received from the peripheral device is converted into the parallel form using serial to parallel conversion and parallel data received from the CPU is converted using serial to parallel conversion. This data is present in modulating form and transmits at a defined baud rate.

Why UART is used?

Protocols like SPI (serial peripheral interface) and USB (Universal Serial Bus) are used for fast communication. When the high-speed data transfer is not required UART is used. It is a cheap communication device with a single transmitter/receiver. It requires a single wire for transmitting the data and another wire for receiving.

UART Communication Protocol - How it works? - Codrey Electronics (1)

It can be interfaced with a PC (personal computer) using an RS232-TTL converter or USB-TTL converter. The common thing between RS232 and UART is they both don’t require a clock to transmit and receive data. The Uart frame consists of 1 start bit, 1 or 2 stop bits and a parity bit for serial data transfer.

Block Diagram

The UART consists of the following core components. They are the transmitter and receiver. The transmitter consists of the Transmit hold register, Transmit shift register, and control logic. Similarly, the receiver consists of a Receive hold register, Receiver shift register, and control logic. In common, both the transmitter and receiver are provided with a baud rate generator.

The baud rate generator generates the speed at which the transmitter and receiver have to send/receive the data. The Transmit hold register contains the data byte to be transmitted. The transmit shift register and receiver shift register shift the bits to the left or right until a byte of data is sent/received.

In addition to these, a read or write control logic is provided to tell when to read/write. The baud rate generator generates speeds ranging from 110 bps (bits per second) to 230400. Mostly, microcontrollers come up with higher baud rates such as 115200 and 57600 for faster data transfer. Devices like GPS and GSM use slower baud rates in 4800 and 9600.

How UART works?

To know the working of UART, you need to understand the basic functionality of serial communication. In short, transmitter and receiver use start bit, stop bit, and timing parameters to synchronize with each other. The original data is in parallel form. For example, we have 4-bit data, to convert it into the serial form, we need a parallel to serial converter. Generally, D flip-flops or latches are used to design the converters.

Working of D – Flip-flop

D flip-flop also known as Data flip-flop shifts one bit from the input side to the output side if and only, when the clock changes the transition from a high state to a low state or low state to a high state. Likewise, if you want to transfer four bits of data you need 4 flip-flops.

Note: Here,

D‘ represents input data.

CLK‘ indicates clock pulses.

Q‘ denotes output data. Now, let’s design a parallel to serial and serial to parallel converter.

Parallel to Serial Conversion

Step#1:

Take 4 Flip-flops. The number of flip-flops is equivalent to the number of bits to be transmitted. Similarly, put Multiplexers in front of each flip-flop, but excluding the first one. A multiplexer is placed to combine the data and convert it to serial bits. It has two inputs, one parallel bit data and another from the previous flip-flop.

Step#2:

Now, Load the data at a time in the D flip-flops. It will pull the parallel data and moves the last bit of last flip-flop (four), and then the third bit, second bit, and finally the first bit. Now, to reconvert the parallel data into serial form serial to parallel converter is used.

Serial to Parallel Conversion

Step#1:

Take 4 Flip-flops. The number of flip-flops is the same as the number of bits to be transmitted.

Step#2:

Initially, disable the parallel bus. Don’t enable until all bits are loaded. Store the data at the input of the first flip-flop. Now make clock high, this will shift the least significant bit to the input of the second flip-flop and the output of the first one. Similarly, shift all the bits one by one by making the clock pulse high. The converter is in the hold state until all bits are transferred to the output.

Step#3:

Now each flip-flop contains one bit of serial data. Erstwhile all bits are transferred to the flip-flop output, enable the bus. This will make the converter to send all the bits at a time.

Protocol Format

The UART starts the communication with a start bit ‘0’. The start bit initiates the transfer of serial data and stop bit ends the data transaction.

It is also provided with a parity bit (even or odd). Even parity bit is represented by ‘0’ (even number of 1’s) and the odd parity bit is represented by ‘1’ (odd number of 1’s).

Transmission

The transmission of data is done using a single transmission line (TxD). Here ‘0’ is considered as space and ‘1’ is known as mark state.

The transmitter sends a single bit at a time. After sending one bit, the next bit is sent. In this way, all the data bits are sent to the receiver with a predefined baud rate. There will be a certain delay in transmitting each bit. For example, to send one byte of data at 9600 baud rate, each bit is sent at 108 µsec delay. The data is added with a parity bit. So, 10 bits of data are required to send 7 bits of data.

Note: In transmission, always LSB (Least Significant Bit) is sent first.

Reception

During the reception, the RxD line (Receiver) is used for receiving the data.

Example of UART interfacing

This example demonstrates the interfacing of ESP8266 UART with MAX232. But, before I jump into the details of interfacing, let me share the pin details of the Max232 driver.

MAX232 IC is powered up by 5V supply which includes a capacitive voltage generator to drive 232 level voltages. It comes with dual transmitters also called the driver (TIN, TOUT) and receivers (RIN and ROUT).

Here, I have used ESP8266 (32-bit microcontroller) which has inbuilt UART. The communication can be done with ESP8266 using AT commands via RS232 to TTL level converter (MAX232). The below figure shows the connection of ESP8266 with PC (personal computer).

By requesting valid AT commands through the PC the Wi-Fi chip will respond with an acknowledgement. I don’t want to go in-depth about ESP8266 and it will be explained in the future tutorials.

Here are the steps to implement serial communication with PC.

  1. Connect Transmitter (TX) of ESP8266 to Receiver (TX) of RS232 to TTL level converter (MAX232) and RX of PC.
  2. Connect Receiver (RX) of ESP8266 to TX of PC and RX of TTL converter.

ESP8266 Commands

AT command (Sent from PC)ESP8266 Response (received by PC)
AT<CR><LF>OK<CR><LF>
AT+CIPMUX=1OK<CR><LF>
AT+CIPSERVER=1,23<CR><LF>OK<CR><LF>

The below screenshot shows the response given by the ESP8266 module.

UART vs USART

USART is the basic form of UART. Technically, they are not the same. But, the definition is the same for both of them. These are microcontroller peripherals that convert parallel data into serial bits and vice versa.

The main difference between UART and USART is, UART supports only asynchronous communication, whereas USART support synchronous as well as asynchronous communication. For easy understanding, here is the comparison between USART and UART.

UARTUSART
The Clock is generated internally by the microcontroller.The sending device will generate the clock.
The data rate is slow.The data rate is higher due to external clock.
Standalone protocolSupports multiple protocols like LIN, RS-485, IrDA, Smart Card etc.
The baud rate should be known before transmission.No need to know the baud rate earlier.
Suitable for low speed communications Suitable for high speed communications.
Reduced energy footprint.Handles serial communication during high energy consumption

RS232 and UART

Logic levels represent the operating voltage levels that a device can withstand to operate in a safe zone. Here are the voltage levels for RS232 and TTL.

RS232 Logic:

RS232 Voltage Levels

Logic LevelVoltage Range
Logic High or OFF output-5V to -15V
Logic Low or ON output+5V to +15V
Logic High or OFF input-3V to -15V
Logic Low or ON input+3V to +15V

In most cases RS232 levels range from -12V to +12V. For instance, an ASCII value for a character ‘A‘ in RS232 is 65 and 41 in Hexadecimal. So in an 8-bit binary format, it is 0100 0001. The RS232 signals are represented as inverted logic. Logic level ‘0’ is shown as ‘1’ and Logic level ‘1’ is shown as ‘0’. The data transmission of RS232 begins with a start bit (0) followed by 8 data bits (LSB first) and a stop bit.

Here shows the representation of RS232 logic levels for ASCII ‘A‘.

UART Communication Protocol - How it works? - Codrey Electronics (14)

TTL/CMOS Logic:

The UART works on TTL logic. The voltage level of TTL ranges from 0 to 5V, represented with no inversion.

UART Communication Protocol - How it works? - Codrey Electronics (15)
  • Initially, the serial line is in the idle state commonly called a Mark state (Logic 1). Now, the data transmission begins with a start bit (logic 0).
  • Further, eight data bits are sent over the serial line one after another with LSB (Least significant bit) first.
  • After the entire transmission is over, a stop bit (logic 1) is encountered.

Advantages

The advantage of UART is, it supports full-duplex communication using two wires. Also, it requires no external clock for data communication. It supports error checking using a parity bit and the length of the data can be changed easily.

Disadvantages

The major disadvantage of UART is, it doesn’t support multi-slave or multi-master configuration. And, the size of the data packet is limited to 9 bits. The UART is not suitable for heavy lifting serial communication during high energy consumption.

Applications

  1. Serial debug port uses the UART driver to print out the data coming from the external world.
  2. We can use it to send and receive commands to and from the embedded devices.
  3. Communication in GPS, GSM/GPRS modem, Wi-Fi chips, etc operates with UART.
  4. Used in Mainframe access to connect different computers.
UART Communication Protocol - How it works? - Codrey Electronics (2024)

FAQs

How does the UART communication protocol work? ›

The transmitting UART is connected to a controlling data bus that sends data in a parallel form. From this, the data will now be transmitted on the transmission line (wire) serially, bit by bit, to the receiving UART. This, in turn, will convert the serial data into parallel for the receiving device.

How do the UART transmitter and receiver synchronize the data transmission and reception? ›

The receiving UART then converts the serial data back to its parallel form so that the receiving device can process it accordingly. The data is transmitted here asynchronously. This means there is no need for the clock signals to synchronize the output bits from the transmitter to the sampling bits of the receiver.

How do I know if my UART is working? ›

A very helpfull and simple testtool : Take 1 male and 1 female 9-pole connector and connect all pins 1:1. When connecting this in-between the computer and your board, you can determine : * Is the MAX-232 chip working connectly : this one always outputs +12 or -12V signals, so one of the leds must light.

What is a real life example of UART? ›

A practical example of UART communication involves connecting a microcontroller to a computer. Consider a scenario where a temperature sensor is connected to a microcontroller, and the microcontroller sends the temperature readings to a computer for display.

How far can UART transmit? ›

UART has a max communication distance of 15 meters. UART leverages shift registers to convert serial communication to parallel communication. UART is commonly used as a “serial port” on computers or in microcontrollers. UART supports full-duplex communication.

How does communication protocol work? ›

A communications protocol is a set of formal rules describing how to transmit or exchange data, especially across a network. A standardised communications protocol is one that has been codified as a standard. Examples of these include WiFi, the Internet Protocol, and the Hypertext Transfer Protocol (HTTP).

How does UART work without a clock? ›

Data flows from the Tx pin of the transmitting UART to the Rx pin of the receiving UART: UARTs transmit data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART.

How many wires are used in UART communication? ›

UART is very simple and only uses two wires between transmitter and receiver to transmit and receive in both directions. Both ends also have a ground connection.

How many devices can be connected to the UART simultaneously? ›

ProtocolUARTI2C
ComplexitySimpleEasy to chain multiple devices
SpeedSlowestFaster than UART
Number of devicesUp to 2 devicesUp to 127, but gets complex
Number of wires12
2 more rows
Sep 25, 2019

How do I receive data from UART? ›

Let's start with the simplest method i.e using the POLL method. The data is Received in blocking mode i.e the CPU will block every other operation until the data Reception is complete. This method is good to use if you are only using UART and nothing else, otherwise all other operations will be affected.

Does UART have flow control? ›

"Instead of having a prearranged baud rate, one of the two devices can send out a clock signal, a square wave at the baud frequency. This clock signal is used to synchronize the two devices, getting rid of the need for the devices to have precise baud clocks." and USART it also provides flow control.

What are the errors in UART transmission? ›

Sometimes, UART errors may be caused by unexpected events or conditions that interrupt or affect the normal flow of data. For example, you may encounter buffer overflow, framing error, parity error, or timeout error. To handle these errors and exceptions, you need to write some code to detect and respond to them.

Which is the most commonly used UART? ›

Which is the most commonly used UART? Explanation: The Intel 8253, 8254 and 8259 are timers whereas Intel 8250 is a UART which is commonly used.

What is the full function of UART? ›

The universal asynchronous receiver-transmitter (UART) takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes.

Is UART a Bluetooth? ›

The Bluetooth UART service allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks which are intended to be joined together.

How does UART RTS and CTS work? ›

Module UART CTS is an input and is connected to the host's RTS, which consequently is an output. The host is able to tell the module it is available to accept data over the UART by controlling its RTS output which signals to the module via the module CTS input. So the module will not send data unless CTS is asserted.

How is data detected in an UART? ›

How is data detected in a UART? Explanation: The data can be detected by the local clock reference which is generated from the baud rate generator.

Can UART transmit and receive at the same time? ›

The UART is full-duplex - this means that it can both send and receive at the same time. The hardware for sending is separate from the hardware for receiving - so they can operate in parallel.

Top Articles
Spring Tx Radar
Aita For Divorcing My Husband Over What My Mil Said
Burkes Outlet Credit Card Sign In
Myra's Floral Princeton Wv
Saccone Joly Gossip
Best Internists In Ft-Lauderdale
University of Louisville Libraries on LinkedIn: #bannedbooks #censorship #uofl #firstamendment #studentlife #librarylife
Fresenius Medical Care to launch 5008 dialysis machine: improved patients` quality of life and efficient use of resources
123Movies The Idol
Subject Guides: Business: Exchange Rates: Historical Foreign Exchange Rate
911 Active Calls Caddo
New Stores Coming To Canton Ohio 2022
The Land Book 9 Release Date 2023
Gt7 Roadster Shop Rampage Engine Swap
Telegraph Ukraine podcast presenter David Knowles dies aged 32
Bullocks Grocery Weekly Ad
Terraria Melee Build Progression Guide & Best Class Loadouts
‘An affront to the memories of British sailors’: the lies that sank Hollywood’s sub thriller U-571
Folsom Gulch Covid
Pokemon Fire Red Download Pc
Times Thanksgiving Meals
5 high school boys cross country stars of the week: Sept. 13 edition
How 'The Jordan Rules' inspired template for Raiders' 'Mahomes Rules'
Hotleak.vip
Www.burlingtonfreepress.com Obituaries
Vanessa Garske Reddit
Panic at the disco: Persona 4 Dancing All Night review | Technobubble
Craigslist Battle Ground Washington
Tamilyogi. Vip
Q102 Snow Desk
Days Till Dec 6
Wild Fork Foods Login
Gay Cest Com
Forum Train Europe FTE on LinkedIn: #freight #traffic #timetablingeurope #fted
‘There’s no Planet B’: UNLV first Nevada university to launch climate change plan
Find Words Containing Specific Letters | WordFinder®
FirstLight Power to Acquire Leading Canadian Renewable Operator and Developer Hydromega Services Inc. - FirstLight
Карта слов и выражений английского языка
Nbc Breaking News Nyc
T-Zell-Leukämie mit großen granulären Lymphozyten - Altmeyers Enzyklopädie - Fachbereich Innere Medizin
How to get tink dissipator coil? - Dish De
No hard feelings: cómo decir "no" en inglés educadamente y sin herir sensibilidades
Police in Germany arrest 25 people allegedly planning to overthrow the government
Cbs Sportsline Fantasy Rankings
123Movies Iron Man 2
Henkels And Mccoy Pay Stub Portal
Every Act That's Auditioned for AGT Season 18 So Far
Neo Geo Bios Raspberry Pi 3
Before Trump, neo-Nazis pushed false claims about Haitians as part of hate campaign
Jailfunds Send Message
Mri Prospect Connect
Deciphering The &quot;sydneylint Leaked&quot; Conundrum
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 5540

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.