Basics of UART Communication (2024)

Posted by Scott Campbell | DIY Electronics | 80

Basics of UART Communication (1)

Remember whenprinters, mice, and modems had thick cables with those huge clunky connectors? The ones that literally had to be screwed into yourcomputer? Those devices were probably usingUARTs to communicate withyourcomputer. While USB has almost completely replaced those old cables and connectors, UARTs are definitely not a thing of the past. You’ll find UARTs being used in many DIY electronics projects to connect GPS modules, Bluetooth modules, andRFID card reader modulesto your Raspberry Pi, Arduino, or other microcontrollers.

Basics of UART Communication (2)

UART stands for Universal Asynchronous Receiver/Transmitter. It’s not a communicationprotocol like SPI and I2C, but a physical circuit in a microcontroller, or a stand-alone IC. AUART’s main purpose is to transmit and receive serial data.

One of the best things about UART is that it only uses two wires to transmit data between devices.The principles behind UART are easy to understand, but if you haven’t readpart one of this series, Basics of the SPI Communication Protocol, that might be a good place to start.

Introduction to UART Communication

In UART communication, twoUARTs communicate directly with each other. The transmitting UART converts parallel data from a controlling device like a CPU into serial form, transmits it in serial to the receiving UART, which then converts the serial data back into parallel data for the receiving device. Only two wires are needed to transmit data between two UARTs. Data flows fromthe Tx pin of the transmitting UART to the Rx pin of the receiving UART:

UARTs transmit data asynchronously, whichmeans there is no clock signal to synchronize the output of bits from the transmitting UART to the samplingof bits by the receiving UART. Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the receiving UART knows when to start reading the bits.

When the receiving UART detects a start bit,it starts to readthe incoming bitsat a specificfrequency known as the baud rate. Baud rate is a measure of the speed of data transfer,expressed in bits per second (bps).Both UARTs must operate at about the same baud rate. The baud rate between the transmitting and receiving UARTs can only differby about 10% before the timing of bits gets too far off.

Both UARTs must also must be configured to transmit and receive the same data packet structure.

How UART Works

The UART that is going to transmit data receives the data from a data bus. The data bus is used to send data to the UART by anotherdevice like a CPU, memory, or microcontroller. Data is transferred from the data busto the transmitting UART in parallel form. After the transmitting UART gets theparallel data from the data bus, it adds a start bit, a parity bit, and a stop bit, creating the data packet. Next,the data packet is output serially, bit by bit at the Tx pin. The receiving UART reads the data packet bit by bit at its Rx pin. The receiving UARTthen converts the data back into parallel formand removesthe start bit, parity bit, and stop bits. Finally, the receiving UART transfers the data packet in parallel to thedata bus on thereceiving end:

UART transmitted data is organized into packets. Eachpacket contains1 start bit, 5 to 9 data bits (depending on the UART), an optional parity bit, and1 or 2 stop bits:

Start Bit

The UART data transmission line is normally held at a high voltage level when it’s nottransmitting data. To start the transfer of data, the transmitting UART pulls the transmission line from high to low for one clock cycle. When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at the frequency of the baud rate.

Data Frame

The data frame contains the actual data being transferred. It can be 5 bits up to 8 bits long if a parity bit is used. If no parity bit is used, the data frame can be 9 bits long. In most cases, the data is sent with the least significant bit first.

Parity

Parity describes the evenness or oddness of a number. The parity bit is a way forthe receiving UART to tell if any data haschanged during transmission. Bits can be changed byelectromagnetic radiation, mismatched baud rates, or long distance data transfers. After the receiving UART reads the data frame, it counts the number of bits with a value of 1 and checks if the totalis an even or odd number.If the parity bit is a 0 (even parity), the 1 bits in the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bits in the data frame should total to an odd number. Whenthe parity bit matches the data, the UART knows that the transmission was free of errors. But if the parity bit is a 0, and the total is odd; or the parity bit is a 1, and the total is even, the UART knows that bits in the data frame have changed.

Stop Bits

To signal the end of the data packet, the sending UART drives the data transmission line from a low voltage to a high voltage for at least two bit durations.

Steps of UART Transmission

1. The transmitting UARTreceives data in parallel from the data bus:

2. The transmitting UART adds the start bit, parity bit, and the stop bit(s) to the data frame:

3. The entire packet is sent serially from the transmitting UART to the receiving UART. The receiving UARTsamples the data line at the pre-configured baud rate:

4. The receiving UART discards the start bit, parity bit, and stop bit from the data frame:

5. The receiving UART converts the serial data back into parallel and transfers it to the data bus on the receiving end:

Advantages and Disadvantages of UARTs

No communication protocolis perfect, but UARTs are pretty good at what they do. Here are some pros and cons to help you decide whether or not they fit the needs of your project:

Advantages

  • Only uses two wires
  • No clock signal is necessary
  • Has a parity bit to allow for error checking
  • The structure of thedata packet can be changedas long as both sides are set up for it
  • Well documented and widely used method

Disadvantages

  • The size of the data frame is limited to a maximum of 9 bits
  • Doesn’t support multiple slave or multiple master systems
  • The baud rates of each UART must be within 10% of eachother

Continue on to part three of this series, Basics of the I2C Communication Protocolto learnabout another way electronic devices communicate. Or if you haven’t already, check out part one, Basics of theSPI Communication Protocol.

And as always, let us know in the comments if you have questions or anything else to add! If you liked this article and want to see more like it, be sure to subscribe- we send out an email when ever we publish new posts.


Related Posts

How to Troubleshoot Electronic Circuits

April 1, 2021

A Complete Guide to Optoelectronic Devices

April 12, 2021

Introduction to Digital Logic Chips

November 15, 2021

Transistors: A Closer Look

October 18, 2021

80 Comments

  1. vivekon June 2, 2016 at 4:43 am

    Nice one. But there is a scope of introducing RS232 concept here

    Reply

    • Taskeenon September 10, 2017 at 1:54 pm

      Thank you for this beautiful explanation.. Great

      Reply

      • Graham Lamberton April 21, 2020 at 2:35 pm

        You say in 2 places it only uses 2 wires. If you want tx and rx you need a ground wire as well. ie It must use 3 wires not 2

        Reply

        • dhruv busaon October 18, 2022 at 1:23 pm

          right you need a ground wire

          Reply

    • Anujon March 22, 2019 at 4:37 am

      As follow up articles yes to both- RS232 &RS485.
      But so often than not we consider UART to be a protocol. And consider RS232 and UART as the same thing.
      In that aspect, not mentioning the protocols here is good decision.

      Reply

  2. Dinesh Yadavon September 26, 2016 at 7:09 am

    Its Beautifully Explained. Frankly Speaking, After a hell lot of search over Internet and books, THis is the only Place where I literally Understood what Exactly UART is and its working.
    Thanks a Lot guys.

    A request: can you write another article to Explain How Exactly an IC (made of transistors) Adds these bits (Start,parity,stop) and Removes them. I mean how exactly they do this intelligent stuff at Electronics level ? Please explain its Circuit basics. :)

    Reply

  3. VIKAS S DEVon September 26, 2016 at 7:21 am

    Well Explained and Nice Article.Thank You :)

    Reply

  4. rekula ravitejaon October 4, 2016 at 12:36 pm

    It’s a good explanation.

    Reply

  5. Ramesh Moteon October 8, 2016 at 8:00 pm

    its very good explanation. thnks a lot.

    Reply

    • dayaon April 23, 2018 at 11:31 am

      You are welcome Mote Saand

      Reply

  6. Volthaus Electronics Laboratoryon October 11, 2016 at 3:50 am

    Excellent.

    Reply

  7. Randallon October 24, 2016 at 4:34 pm

    This was helpful but I’m unsure about one thing. If two bits gets flipped in error, wouldn’t the total still match with the parity bit? Or more generally, if an even number of bits get flipped in error, the error won’t be detected. Is that right?

    Reply

    • Rickyon October 27, 2016 at 6:32 pm

      Correct, the receiver will not notice the error, but, pending good design of the hardware, this is going to be a rare case.

      Reply

    • ArchonOSXon December 18, 2016 at 2:17 pm

      Your analysis is correct. That is why parity checking is rudimentary and may not prevent all errors. But the odds of two bits being changed is much higher than just one so this method works in most cases of low level hardware communication.

      Reply

  8. Olivia Christyon November 4, 2016 at 7:01 am

    Nice work. As a begginer this helps me a lot .can you do this for uart with interrupts also

    Reply

  9. rajkumaron November 30, 2016 at 9:58 am

    Well explanation

    Reply

  10. hardik tankon December 3, 2016 at 6:10 am

    well explanation,and its easy to understand
    friendly explanation ,,nice
    thanx

    Reply

  11. sakson December 7, 2016 at 4:44 am

    really easy of understanding and way of explanation is good

    Reply

  12. haleemon December 11, 2016 at 3:38 pm

    Nice one!

    Reply

  13. vjon December 16, 2016 at 1:05 pm

    very good expaination. I have one question that we also use Usb micro port for connectiing uart hardware and the other USB port type A to our laptop. How does it work? does uart support USB ports also?

    Reply

    • Harshalon January 4, 2017 at 10:40 am

      no uart does not support the usb ports

      Reply

  14. OFon December 20, 2016 at 11:07 pm

    “It’s not a communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or as a separate IC”.

    This part confuses me. I understand that UART is a physical hardware IC, but it must also be a protocol because how else would there be communication? The bits can’t just be sent randomly. Data is sent through packets just like you described in a timely matter and specific order. Isn’t that in essence a protocol? Thanks.

    Reply

    • Tom Son December 20, 2017 at 7:27 am

      It is a very confusing statement, because I2C and SPI perform a similar low level task – transmitting and receiving bytes between devices.

      A UART doesnt have to be a physical IC, and it doesnt even need to be circuitry inside a microcontroller – just like I2C and SPI it can be implemented entirely in software by “bit banging” general purpose I/O pins.

      Reply

  15. rk yadavon December 22, 2016 at 5:40 am

    good explanation to thanks

    Reply

  16. karthikon January 2, 2017 at 11:02 am

    thanks for the good information. simple and best.

    Reply

  17. nagul shariefon January 19, 2017 at 10:05 am

    i’m not understanding of parity bit

    Reply

    • Harshalon February 2, 2017 at 4:47 am

      Parity bit is that it show that how many bit are there and if there are even number is there then it will pass bit 1 or bit 0

      Reply

  18. Syed Ibrahimon March 8, 2017 at 4:19 am

    Good post. Its in a language everyone can understand. But i also want to know how communication (data transfer) between data bus and UART occurs.

    Reply

  19. ankur singhon March 21, 2017 at 10:12 am

    It is really a very good explanation as i m not from electrical background.

    Reply

  20. Chandruon March 23, 2017 at 8:33 am

    Can anyone say how can I transmit 1000 bytes of data through uart protocol

    Reply

  21. k t ron April 4, 2017 at 12:26 pm

    Awsome explenation really

    Reply

  22. Hemavathion May 15, 2017 at 8:25 am

    Really good explaination. Now i understood very clearly what exactly The UART performs internally

    Reply

  23. thoshif khanon July 12, 2017 at 6:30 am

    i am working on UART so any body can send VHDL CODE to my mail thoshifkhan1992@gmail.com

    Reply

  24. k.sudheer kumaron July 13, 2017 at 5:11 am

    It is an nice explanation .Thank you

    Reply

  25. Flash9325on September 26, 2017 at 11:21 pm

    1) The two UARTs communicating having the same baud rate, does that mean the clocks of both the UARTs are synchronized ( i.e clock cycle starts and stops at the same time) ?

    I didnt get from where that allowed difference of 10% came from. Can you please explain!!!

    Reply

    • RKon November 27, 2017 at 9:50 am

      Thank you soo much.. Thanks a ton. Really U ppl had done a great job. Now seriously I understood the working principle, data transmission of bits and everything without any doubt. Thanks again and again. Hope you upload more and more sessions and concepts like this.

      Reply

    • Tom Storeyon December 20, 2017 at 8:14 am

      The clocks of the two systems do not need to be synchronised in any way, and they can run at entirely different speeds.

      UART is self-timed – each individual bit occupies a specific amount of time based on the configured baud rate, e.g. ~104uS at 9600 baud (1 / 9600). So the key to making this work, using 9600 baud as an example, is that the transmitter needs to alternate the TX pin at 104uS intervals, and the receiver needs to sample its RX pin at 104uS intervals to reconstruct what has been sent. The receiver starts this process once it sees the start bit.

      If the transmitter or receiver differ significantly enough in this measurement because they have such different baud rates configured, then the rate at which the transmitter alternates its TX pin and the rate that the receiver samples its RX pin means you either miss entire bits, or read the same bit more than once.

      10% of error is way too much and is a bad suggestion. See: https://www.allaboutcircuits.com/technical-articles/the-uart-baud-rate-clock-how-accurate-does-it-need-to-be/

      Reply

      • thomason June 18, 2019 at 12:31 pm

        So its not possible to communicate between two mcu’s with different clock speeds?

        Reply

  26. Harion October 30, 2017 at 6:55 am

    Why we using 9bits institute data transmission

    Reply

  27. Karthik gvon December 20, 2017 at 7:23 am

    After a long days after completing engineering understood the concept of UART
    Thanks for sharing.

    Reply

  28. OGBONNA VITALISon February 26, 2018 at 11:45 pm

    Nice one…where can/is this UART protocol applied. Which module uses this protocol

    Reply

  29. vineeshvson May 28, 2018 at 6:00 am

    Good one.

    Reply

  30. navaneethon May 28, 2018 at 9:29 am

    why we use ground in the uart communication as a common terminal to both transmitter and receiver.

    Reply

    • lcabson June 30, 2018 at 6:31 am

      You need that third wire (GND) for electrical purposes. Both devices have to agree on a voltage reference. Otherwise, the meaning of 1s and 0s would be lost.

      Reply

  31. Madhu s gon October 5, 2018 at 4:47 pm

    A fantastic explanation ever about UART!

    Reply

  32. MauriciOon October 25, 2018 at 7:05 am

    Nice explanation! Suggestion to add: if two bits change during the transmission of the datapacket then the Parity bit error check doesn’t work. So it’s a rather weak form of error checking.

    Reply

    • erikaon January 30, 2019 at 6:17 am

      Thanks for the feedback, I am going to improve the UART technology pretty soon, stay tuned for updates!

      Reply

  33. jawad haidaron January 9, 2019 at 3:44 pm

    Great explanation. if the baud rate is 9600 bits per second, this means that every 1/9600 second am sending a bit, this raises the following question, the time between sending two consecutive bits, what’s happening in this time? the serial line getting back to zero, right?

    Reply

  34. chalith lakshanon February 5, 2019 at 2:23 am

    Wow its a great article. Can u guyz just upload the ‘C codes’ happening inside the transmission and receiving.
    That will be great!!!

    Reply

  35. MaaNDAon February 8, 2019 at 5:14 am

    I love it

    Reply

  36. kishoreon February 20, 2019 at 9:57 am

    Really very good explanation, pls keep going posting on updates

    Reply

  37. PrASHANTon April 2, 2019 at 5:20 am

    That was just awesome.I was totally new to the world of electronics and I don’t even know what the UART is?Now I got to know in just a single reference of yours that what a UART is and how it works.This helped me a lot in my final project…MY BIG BIG Thanks to you.

    Reply

  38. Sravyaon April 10, 2019 at 9:39 am

    Yeah! Really nice explanation in an easy manner

    Reply

  39. Muthukumaron April 16, 2019 at 5:47 am

    Good Explanation…

    Reply

  40. Raghuon April 17, 2019 at 12:25 pm

    Great explanation with simple words. Anyone even without a prior knowledge of communication protocols can learn the concept perfectly with the help of this article. Thank you!

    Reply

  41. VIJAYon May 4, 2019 at 11:45 am

    Why we are connecting common ground in UART..
    Please cover this point also..

    Reply

  42. ELANGOVAN KUMARon May 30, 2019 at 2:35 pm

    what will happen if RX uart is in off state and TX uart is started transmission(both are physically connected).
    how TXuart will come to know whether RX uart received or not.

    Reply

  43. KrUpaon June 8, 2019 at 9:40 am

    ‘If the parity bit is a 1 (odd parity), the 1 bits in the data frame should total to an odd number.”
    This line is under the parity paragraph.
    I think the 1 bits in the data frame should total to an even number because data frame includes data of size 5-8(data frame) where the next bit is a parity. For odd parity(parity bit as 1) the sum of 1 bits has to be even in the data frame.

    Reply

  44. Satish Chappidion July 2, 2019 at 6:41 am

    NICE EXPLANATION BRIEFLY ………
    GIVE SUGGESTIONS GET ORIGINAL DATA SHEET OF UART ……

    Reply

  45. 50BAR lpg cylinderon July 13, 2019 at 7:56 am

    ld include mainly propane mixtures, most commonly propane and butane mixtures. Mixtures contain more propane in winter in the northern hemisphere and more butane in summer.

    In the United States,cooking gas cylinder two grades of liquefied petroleum gas are mainly sold: commercial propane and HD-5. Propane/butane mixtures are also listed in these specifications.
    Propylene, butene and various other hydrocarbons are also commonly present in small concentrations. HD-5 will limit the propylene content that can be placed in LPG to 5% and be used as an automatic gas specification.

    Strong odorant ethanethiol, easy to detect
    A powerful odorant, ethanethiol, was added to make leaks easy to detect. The internationally recognized European standard is EN 589. In the United States, Tetrahydrothiophene (thiophene) or amyl mercaptan are also approved, although they are not currently used.
    LPG is prepared by refining oil or “wet” natural gas, almost entirely from fossil fuel sources, and is manufac

    Reply

  46. Srahason July 30, 2019 at 8:17 am

    As you explained above
    In parity check when ever the UART Rx will get to know that the data frame had changed, will it send a request for original data frame or what it is going to do after knowing the data frame had changed ??

    Reply

  47. Jton September 14, 2019 at 5:00 pm

    Best damn explanation yet!

    Reply

  48. Rameshon September 20, 2019 at 1:12 pm

    UART is full duplex or half duplex

    Reply

    • Daniel Selvan Don September 17, 2021 at 4:51 am

      The UART component can be configured for Full Duplex, Half Duplex, RX only or TX only versions. All versions provide the same basic functionality differing only in the amount of resources utilized

      Ref: https://www.cypress.com/file/132486

      Reply

  49. Moulikaon September 30, 2019 at 7:02 am

    Can I know why it’s not called a communication protocol still two UART’s have to communicate with Tx and Rx signals as in SPI : MOSI, MISO?

    Reply

  50. Nayanaon October 12, 2019 at 8:57 am

    Thank you very much. It is explained very well for beginners.

    Reply

  51. Mallikaon November 12, 2019 at 11:35 am

    Very good material. Please upload CAN protocol also.
    Thank U

    Reply

  52. Gowtham Ron December 12, 2019 at 4:56 am

    Hello Sir,

    As you said due to Electromagnetic Radiation Data bits can change..! and Error can be detected by the Receiver
    What if Data bits doesn’t change and the parity bit got change due to radiation..??

    Reply

    • Peteron May 10, 2024 at 12:33 am

      There you are, found you at last !

      For so many years I’ve been looking for you.
      But now I have you by the short and curlies.
      You won’t escape again.

      PS FOR THE OTHERS :
      This is the guy who fell out of that black hole.

      Reply

  53. avion January 4, 2020 at 5:02 pm

    how does the receiver distinguish between a data bit and stop bit. In ‘Steps of UART transmission’ step #3, diagram shows that the last bit transmitted is 1 – how can receiver distinguish between this and any other data bit.

    Reply

  54. Naveen kumaron January 8, 2020 at 8:45 am

    Hi,
    May I know the Use of Rx Pin of UART Transmitter and Tx Pin of UART Receiver while the Data Transmission is happening from Tx Pin of UART Transmitter to Rx Pin of UART Receiver

    Reply

  55. Curie Guptaon April 18, 2020 at 7:30 am

    Thank you for the clear explanation.
    Looking forward to more such articles.

    Reply

  56. Cassim peeron August 7, 2020 at 1:24 am

    I have a Project with 5 LX-16A Bus Servos.
    I have LewanSoul Bus Servo Controller
    I need to setup a Coordinated Action
    I need to set the servo motors to swing 180 degrees
    ID 1 will start and return to 0 degrees.
    ID 2 will start 5 to 10 seconds after ID 1
    ID 3 will start 5 to 10 seconds after ID 2
    ID 4 will start 5 to 10 seconds after ID 3
    ID 5 will start 5 to 10 seconds after ID 4.

    I have No knowledge of electronic communication.
    Your UART explanation has opened a new window.
    Can you help setting these Data Packets for the Coordinated Action.
    Alternatively direct me to someone that can help me with this project.
    Thank you
    Cassim
    E:gurupeer@gmail.com

    Reply

  57. Graham Lamberton August 7, 2020 at 6:37 am

    Hi Cassim This was not my article?
    I see it did not say who wrote it?
    Ill try find out

    Reply

  58. logari84on October 9, 2020 at 12:08 pm

    “If the parity bit is a 0 (even parity), the 1 bits in the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bits in the data frame should total to an odd number.”

    This is a little bit misleading and poorly written. Parity bit is not 0 on even parity and 1 in odd parity. Parity bit can be 1 or 0 depending on the situation. In case of even parity, the total number of ‘1’ bits, including the parity bit, should be even. In contrast, in odd parity, the total number of ‘1’ bits, including parity bit, should be odd. So parity bit is either ‘1’ or ‘0’ to satisfy the requirement I described before. An example always makes things more clear.

    Consider transmission of byte ‘10100010’. The number of ‘1’ bits is 3 (odd).
    – Even parity: to make the number of ‘1’ bits even we need one more (3+1 = 4 which is even). Consequently the parity bit should be ‘1’, resulting in transmission of ‘101000101’
    – Odd parity: the number of ‘1’ bits is already odd so we don’t need to add something. Consequently the parity bit should be ‘0’, resulting in transmission of ‘101000100’

    Hope that makes it more clear.

    Reply

  59. Ericon August 28, 2021 at 12:20 am

    Uart, no longer just an acronym. From what I gathered from this awesome write up and using memory of other articles. My thought is the uart, is a shift register with rx\tx on one side and bus inputs filled by mcu, cpu, whatever.laptop uart Tx h, Rx h, chilling. Bus filled (tx L for 1 baud) = start. 5-9 high or lows (1=5v 1baud) (0=0v 1baud} (5-8 if use parity) parity bit (count 1s in 5-8 bits compair to me the parity bit which is not added due to the fact I’m set by the mcu, cpu, or whatever.) Once all my bits are in and the stop bit brings my rx high for 2 or more baud all bits transfer to bus instantly on there own pin, wire whatever, and bam ready for another start bit. Only about 9588 baud left in this second so whatever

    Reply

  60. Caioon October 16, 2021 at 3:26 pm

    Hi, i’ve much enjoyed these basic concepts from the series. Thanks a lot! Can you tell me names of nice books on the subjects (SPI, I²C and UART) ?

    Reply

  61. praveenon May 4, 2023 at 10:10 am

    need explanation on Ethernet communication

    Reply

Leave a reply

Basics of UART Communication (2024)

References

Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5408

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.