askvity

How does UART work?

Published in Serial Communication 4 mins read

UART (Universal Asynchronous Receiver/Transmitter) facilitates serial data communication without a clock signal. It's a widely used protocol for short-distance, low-speed data exchange between two devices. The key is asynchronous transmission.

Asynchronous Communication Explained

Unlike synchronous communication (e.g., SPI, I2C), UART doesn't rely on a shared clock signal for synchronization. Instead, it embeds timing information within the data stream itself. This simplifies wiring (less wires) but requires careful configuration on both the transmitting and receiving ends.

Core Principles

  • Data Framing: UART transmits data in packets (frames) containing:

    • Start Bit: Signals the beginning of transmission (usually logic low).
    • Data Bits: The actual data being transferred (typically 8 bits, but can be 5-9).
    • Parity Bit (Optional): Used for basic error detection.
    • Stop Bit(s): Signals the end of transmission (usually logic high, one or two bits).
  • Baud Rate: Represents the data transfer rate (bits per second). Both the transmitter and receiver must be configured with the same baud rate for successful communication. Common baud rates include 9600, 115200, etc.

  • Asynchronous Nature: According to the reference material, the UART interface "transmits data asynchronously." The transmitter creates the bitstream based on its clock signal, while the receiver uses its internal clock signal to sample incoming data. This is the defining feature.

Steps Involved in UART Communication

  1. Idle State: The UART line is typically held at a logic high voltage level when no data is being transmitted.
  2. Start Bit Transmission: The transmitter pulls the line low to signal the start of a new data frame.
  3. Data Bit Transmission: The transmitter sends the data bits, one after another, according to the configured baud rate. Least significant bit (LSB) is typically sent first.
  4. Parity Bit Transmission (if enabled): A parity bit (even or odd) is sent for error detection.
  5. Stop Bit Transmission: The transmitter sends one or more stop bits (logic high) to indicate the end of the frame.
  6. Receiver Sampling: The receiver detects the start bit and begins sampling the incoming data bits at the agreed-upon baud rate. Because of the absence of a clock signal, the receiver relies on its internal clock and the configured baud rate to determine when to sample each bit.
  7. Data Reconstruction: The receiver reassembles the data bits into a byte or word.
  8. Error Checking: The receiver checks the parity bit (if present) to detect transmission errors.
  9. Frame Processing: The receiver processes the received data and prepares for the next incoming frame.

Example

Let's say we want to send the ASCII character 'A' (0x41 or 01000001 in binary) using UART with the following settings:

  • Baud Rate: 9600
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1

The transmitted frame would look like this:

Start Bit (0) + Data Bits (10000010) + Stop Bit (1)
  • The start bit signals the beginning.
  • The data bits represent the ASCII value of 'A' (LSB first, so 10000010).
  • The stop bit indicates the end of the frame.

Advantages of UART

  • Simplicity: Easy to implement in hardware and software.
  • Low Cost: Requires minimal hardware.
  • Widely Supported: Available on most microcontrollers and computers.
  • No Clock Signal Required: Reduces wiring complexity, as stated in the reference.

Disadvantages of UART

  • Lower Speed: Not suitable for high-speed data transfer.
  • No Hardware Addressing: Only supports point-to-point communication (one transmitter, one receiver).
  • Error Detection Limited: Parity checking provides only basic error detection.
  • Baud Rate Synchronization: Both devices must be configured with the same baud rate, which must be determined in advance or during the initial handshake (if implemented).

Common Applications

  • GPS Modules: Communicating location data to a microcontroller.
  • Bluetooth Modules: Establishing wireless communication links.
  • Serial Terminals: Interacting with embedded systems.
  • Sensor Communication: Receiving data from sensors.

In summary, UART is a simple and widely used asynchronous serial communication protocol that transmits data in frames, relying on the configured baud rate and start/stop bits for synchronization instead of a dedicated clock signal.

Related Articles