UART Communication Protocol - How It Works - Codrey Electronics
UART Communication Protocol - How It Works - Codrey Electronics
- Codrey Electronics
SPONSORED SEARCHES
In this tutorial, you will learn the basics of UART communication, and working of the UART.
What is UART?
“UART” stands for Universal Asynchronous receiver-transmitter. It is a 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.
UART Interface
It can be interfaced with a PC (personal computer) using a 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. They use 1 start, 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 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 baud rate such as 9600, 115200.
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 2/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Working of D – Flip-flop
Basic 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 high state to 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,
‘Q‘ denotes output data. Now, let’s design a parallel to serial and serial to parallel converter.
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 3/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
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.
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 4/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
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
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 5/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
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.
Protocol format
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.
Transmission Frame
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.
Reception
During the reception, RxD line (Receiver) is used for receiving the data.
Receive Frame
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 6/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
MAX232 Pinout
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).
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 7/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
By requesting valid AT commands through the PC the Wi-Fi chip will respond with an acknowledgment.
I don’t want to go in-depth about ESP8266 and it will be explained in the future tutorials.
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=1 OK<CR><LF>
AT+CIPSERVER=1,23<CR><LF> OK<CR><LF>
The below screenshot shows the response given by the ESP8266 module.
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.
UART USART
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 8/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
UART USART
The Clock is generated internally by the The sending device will generate the clock.
microcontroller.
The data rate is slow. The data rate is higher due to external clock.
The baud rate should be known before No need to know the baud rate earlier.
transmission.
Suitable for low speed communications Suitable for high speed communications.
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:
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 8-bit binary format, it is 0100 0001. Here shows the
representation of RS232 logic levels for ASCII ‘A‘.
Related Posts:
1. What is RS232 Protocol and How it Works?
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 9/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Leave a Comment
Comment
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 10/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Recently Published
Light Intensity to
Frequency Converter
Module
DC Voltage
Booster/Multiplier
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 11/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Categories
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 12/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Analog Circuits
Analog Electronics
Arduino Projects
Books
Circuit Elements
DC Circuits
Electronic Circuits
Electronics
Embedded Systems
Fundamentals of Electricity
Learn
Microcontroller
Microcontroller Projects
Microcontrollers
Power Supply
Resistor
Serial Communication
Solar Projects
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 13/14
11/11/2018 UART Communication Protocol - How it works? - Codrey Electronics
Terms of Use Privacy Policy Contact Us Copyright © 2018 Codrey Electronics. All Rights Reserved.
https://www.codrey.com/embedded-systems/uart-serial-communication-rs232/ 14/14