UART Protocol

How UART Protocol Works?

The Universal Asynchronous Receiver-Transmitter (UART) protocol facilitates serial communication by transmitting data one bit at a time. It handles data conversion between parallel an

d serial formats, enabling devices to exchange information effectively. Below is a detailed breakdown of how UART works:

1. Data Conversion: Parallel to Serial and Serial to Parallel

  • Transmitter (Sending Side):
    • The transmitting device (such as a microcontroller or CPU) processes data in parallel form, meaning multiple bits are transmitted simultaneously within the device.
    • Before sending data over a serial communication line, the UART module converts this parallel data into a serial stream (one bit at a time) to reduce the number of physical lines needed for communication.
  • Receiver (Receiving Side):
    • On the receiving side, the UART module takes the incoming serial data and converts it back into parallel form for further processing by the microcontroller or CPU.

2. Step-by-Step Data Transmission Process

a. Data Loading into the UART Module

  • The transmitting device writes data (typically 8 bits) into its UART data register.
  • This data represents the payload to be sent, such as a character or command.

b. Framing the Data

UART Protocol Frame Format
  • To ensure that the data is transmitted and received correctly, the UART module adds specific bits to the data:
    1. Start Bit:
      • A single start bit signals the beginning of a data frame.
      • The line is held at a high voltage (idle state) before transmission, and the start bit pulls the line low to indicate data is about to be sent.
    2. Data Bits:
      • Typically 5 to 9 data bits (configurable) represent the actual payload being transmitted.
    3. Optional Parity Bit:
      • A parity bit is used for simple error detection.
      • The parity can be even or odd, ensuring that the total number of 1s in the data frame is even or odd, respectively.
    4. Stop Bit(s):
      • One or more stop bits indicate the end of a data frame.
      • The line is brought back to its high (idle) state after the stop bit(s).
Example of a Framed Data Packet (8-bit Data):
Start Bit | Data Bits (8) | Parity Bit (Optional) | Stop Bit(s)
   0         11010101             1                     1

c. Sending Data Over the TX Line

  • The UART module transmits the framed data one bit at a time through the TX (Transmit) line.
  • The transmission occurs at a specific baud rate (e.g., 9600 bps, 115200 bps), which determines the speed of data transfer.
  • Both transmitting and receiving devices must agree on the baud rate to synchronize communication.

3. Step-by-Step Data Reception Process

a. Reading Incoming Data on the RX Line

  • The receiving device continuously monitors the RX (Receive) line for any changes in the signal.
  • When it detects a falling edge (high to low transition), it recognizes the start bit and begins reading the incoming data frame.

b. Removing Framing Bits

  • The receiving UART module extracts the data bits from the incoming serial stream, ignoring the start, parity (if any), and stop bits.
  • It ensures that the data frame is received accurately, checking for errors using the parity bit (if enabled).

c. Reconstructing Original Data

  • The extracted data bits are converted back into parallel form and stored in the UART data register of the receiving device.
  • The microcontroller or CPU can then access and process the data for further use.

4. Error Detection and Handling

  • Parity Check (Optional):
    • If parity checking is enabled, the receiver compares the calculated parity with the received parity bit.
    • If there is a mismatch, a parity error is flagged.
  • Framing Errors:
    • If the stop bit is not detected where expected, it indicates a framing error. This can occur due to noise or incorrect baud rate settings.
  • Buffer Overrun Errors:
    • If the UART data register is not read in time before new data arrives, an overrun error occurs.

5. Baud Rate and Synchronization

  • The transmitting and receiving devices must operate at the same baud rate for successful communication.
  • Baud rate mismatch can lead to corrupted data or communication failure.
  • Common baud rates include 9600, 19200, 38400, 57600, and 115200 bps.

6. Full Duplex Communication

UART supports full-duplex communication, meaning data can be transmitted and received simultaneously through separate TX and RX lines.

Example of UART Communication

Scenario: A microcontroller sends the character 'A' (ASCII value 65, binary 01000001) to a PC terminal.

  • Transmitting Device Steps:
    1. Data 'A' is loaded into the UART data register.
    2. The UART transmits the framed data bit by bit through the TX line.
    3. The UART module frames the data as follows:
Start Bit (0) | Data Bits (01000001) | Parity Bit (None) | Stop Bit (1)
  • Receiving Device Steps:
    1. The RX line detects the start bit (falling edge).
    2. The UART extracts the data bits (01000001) and removes the framing bits.
    3. The extracted data is converted back into parallel form and interpreted as 'A'.

UART Workflow

  1. Transmitter Side: Parallel Data → Framed Data → Serial Transmission (TX Line).
  2. Receiver Side: Serial Data (RX Line) → Framed Data → Parallel Data.

The simplicity of UART and its self-synchronizing nature make it a popular protocol for short-distance serial communication in embedded systems, IoT devices, and beyond.

2 thoughts on “UART Protocol”

  1. swarup kumar nath

    Nice Explanation UART (Universal Asynchronous Receiver/Transmitter) Communication protocol Tutorial.

Leave a Reply

Scroll to Top