Universal Asynchronous Receiver-Transmitter (UART)
1. Definition and Purpose of UART
1.1 Definition and Purpose of UART
The Universal Asynchronous Receiver-Transmitter (UART) is a hardware communication protocol that enables serial data transmission between devices without a shared clock signal. Unlike synchronous protocols such as SPI or I2C, UART operates asynchronously, relying on predefined baud rates to synchronize data sampling between transmitter and receiver. This makes it particularly useful in scenarios where minimizing wiring complexity and reducing clock synchronization overhead are critical.
Fundamental Operating Principle
UART communication is character-oriented, transmitting data in discrete frames. Each frame consists of:
- A start bit (logic low) signaling the beginning of transmission.
- 5–9 data bits (typically 8 bits for byte-oriented systems).
- An optional parity bit for error detection.
- 1 or 2 stop bits (logic high) marking the end of the frame.
The baud rate, defined as the number of signal changes per second, must match between transmitter and receiver. Common rates range from 9600 baud in legacy systems to several megabits per second in modern implementations. The receiver samples the data line at a rate of 16x the baud rate to accurately detect the middle of each bit period, minimizing timing errors.
Mathematical Basis of Baud Rate Timing
The time duration of a single bit (Tbit) is inversely proportional to the baud rate (B):
For a system operating at 115200 baud, the bit period is approximately 8.68 µs. The receiver samples the data line at intervals of Tbit/16 to locate the midpoint of each bit. The maximum allowable clock drift between devices is derived from the sampling error tolerance:
For a 115200 baud system, the permissible clock drift is ±7200 Hz, emphasizing the need for accurate oscillator calibration.
Practical Applications and Relevance
UART is widely used in:
- Embedded systems debugging via serial console output.
- Communication between microcontrollers and peripheral modules (GPS, Bluetooth).
- Legacy industrial equipment interfacing due to its noise resilience in electrically harsh environments.
Its simplicity and low hardware overhead make UART a preferred choice for point-to-point communication, though it lacks native support for multi-device networks or hardware collision avoidance.
Voltage Levels and Physical Layer Variations
While traditional UART uses TTL/CMOS voltage levels (0V for logic low, 3.3V/5V for logic high), industrial implementations often employ RS-232 (±3V to ±15V) or RS-485 (differential signaling) for noise immunity. The logical inversion in RS-232 (negative voltage for logic high) necessitates level-shifting ICs like MAX232 when interfacing with TTL-based systems.
Key Characteristics of UART
Asynchronous Communication
UART operates asynchronously, meaning it does not rely on a shared clock signal between the transmitter and receiver. Instead, synchronization is achieved through predefined baud rates and start/stop bits. The absence of a clock line simplifies hardware design but requires precise timing alignment to avoid data corruption. The baud rate, expressed in bits per second (bps), must match on both devices, with common rates ranging from 9600 bps to 115200 bps in embedded systems.
where Tbit is the duration of one bit period.
Frame Structure
Data transmission in UART follows a standardized frame format:
- Start Bit – A logic-low signal (0) indicating the beginning of a frame.
- Data Bits – 5 to 9 bits of payload, typically 8 bits for byte-oriented systems.
- Parity Bit (Optional) – An error-detection bit (even, odd, or none).
- Stop Bit(s) – Logic-high (1) signaling the end of the frame, usually 1 or 2 bits.
Error Detection Mechanisms
UART employs three primary error-detection methods:
- Parity Checking – Single-bit error detection via even or odd parity.
- Framing Errors – Triggered if the stop bit is not detected at the expected time.
- Overrun Errors – Occur when the receiver buffer is full but new data arrives.
Voltage Levels and Standards
While UART logic is typically TTL (0V for logic 0, 3.3V/5V for logic 1), physical layer standards like RS-232 and RS-485 extend its range:
- RS-232 – Uses ±3V to ±15V for noise immunity, supporting distances up to 15 meters.
- RS-485 – Differential signaling enables multidrop communication over 1200 meters.
Half-Duplex Operation
Most UART implementations are full-duplex (simultaneous transmit/receive), but half-duplex configurations are possible by toggling transmit/receive modes dynamically. This is common in RS-485 networks to avoid bus contention.
Clock Tolerance and Baud Rate Mismatch
UART receivers tolerate slight baud rate discrepancies (typically ≤2–3%) by resynchronizing at each start bit edge. The maximum permissible mismatch is derived from sampling point alignment:
where N is the number of bits per frame (typically 10 for 8N1). For a 10-bit frame, this yields ±5% tolerance, reduced to ±2–3% in practice for reliable sampling.
1.3 Comparison with Other Serial Communication Protocols
UART is one of several serial communication protocols used in embedded systems, telecommunications, and computing. Its characteristics differ significantly from other prevalent protocols such as SPI (Serial Peripheral Interface) and I²C (Inter-Integrated Circuit). Understanding these differences is critical for selecting the optimal protocol for a given application.
UART vs. SPI
SPI is a synchronous, full-duplex serial communication protocol that employs a master-slave architecture with separate clock (SCLK), data in (MISO), data out (MOSI), and slave select (SS) lines. Unlike UART, which is asynchronous, SPI relies on a shared clock signal for synchronization, eliminating the need for precise baud rate matching. This allows SPI to achieve significantly higher data rates, often exceeding 100 Mbps in high-speed implementations.
However, SPI requires more physical connections—typically four or more wires—compared to UART's two-wire (TX and RX) implementation. Additionally, SPI lacks built-in error-checking mechanisms, whereas UART can incorporate parity bits for basic error detection. The absence of addressing in SPI necessitates manual slave selection via dedicated SS lines, making it less scalable for multi-device networks compared to I²C or CAN (Controller Area Network).
UART vs. I²C
I²C is a synchronous, multi-master, multi-slave protocol that uses only two bidirectional lines: serial data (SDA) and serial clock (SCL). Unlike UART, I²C supports multiple devices on the same bus through 7-bit or 10-bit addressing, making it highly scalable for sensor networks and peripheral interfacing. The inclusion of clock synchronization and arbitration mechanisms allows multiple masters to share the bus without collisions.
However, I²C operates at lower speeds (typically 100 kHz in standard mode, up to 3.4 MHz in high-speed mode) compared to UART, which can reach higher baud rates (e.g., 1 Mbps or more) in point-to-point configurations. I²C also introduces protocol overhead due to addressing and acknowledgment bits, reducing effective throughput. UART, being simpler, is often preferred for direct, high-speed communication between two devices where minimal latency is crucial.
UART vs. CAN
CAN is a robust, differential serial protocol designed for automotive and industrial environments. Unlike UART, CAN supports multi-master communication with built-in collision detection and prioritization via message identifiers. Its differential signaling (CAN_H and CAN_L) provides superior noise immunity, making it suitable for electrically noisy environments where UART's single-ended signaling may fail.
However, CAN's complexity—including message framing, error handling, and bit stuffing—results in higher implementation overhead. UART remains preferable for simple, short-range communications where noise immunity is not a primary concern. Additionally, CAN's maximum data rate (1 Mbps at 40 meters) is comparable to UART's, but UART can achieve higher speeds over shorter distances with fewer protocol constraints.
Summary of Key Differences
Protocol | Synchronization | Topology | Speed | Error Handling | Wires |
---|---|---|---|---|---|
UART | Asynchronous | Point-to-point | Up to ~10 Mbps | Optional parity | 2 (TX, RX) |
SPI | Synchronous | Master-slave | Up to ~100 Mbps | None | 4+ (SCLK, MOSI, MISO, SS) |
I²C | Synchronous | Multi-master | Up to ~3.4 Mbps | ACK/NACK | 2 (SDA, SCL) |
CAN | Synchronous | Multi-master | Up to ~1 Mbps | CRC, ACK | 2 (CAN_H, CAN_L) |
In practice, UART is often chosen for its simplicity and low overhead in direct device-to-device communication, while SPI and I²C are favored for multi-device systems requiring higher throughput or addressing capabilities. CAN is reserved for environments demanding robustness and fault tolerance.
2. UART Transmitter and Receiver Blocks
2.1 UART Transmitter and Receiver Blocks
Transmitter Block Architecture
The UART transmitter converts parallel data into a serial bit stream with precise timing. The core components include:
- Transmit Shift Register (TSR): Loads parallel data from the transmit buffer and shifts it out serially, LSB or MSB first, depending on configuration.
- Baud Rate Generator: Derives the bit period clock from the system clock using a programmable divisor. The relationship is given by:
Modern UARTs often use fractional dividers for finer baud rate resolution. The TSR synchronizes with this clock to maintain accurate bit timing.
Framing and Signal Conditioning
Before transmission, the UART encapsulates data with framing bits:
- Start Bit: A logic-low pulse (1 clock cycle) marking the beginning of a frame.
- Stop Bit(s): Logic-high pulses (1, 1.5, or 2 cycles) indicating frame completion.
- Parity Bit (Optional): An error-checking bit appended after data bits (odd, even, or no parity).
The transmitter typically includes a pre-transmission buffer to minimize software overhead. Double-buffering allows loading the next byte while the current one transmits.
Receiver Block Architecture
The receiver samples the serial line at 16x the baud rate (oversampling) for noise immunity. Key components are:
- Start Bit Detector: Triggers on a high-to-low transition validated by 3 mid-bit samples (at 8th, 9th, and 10th oversampling cycles).
- Data Sampler: Captures bits at the theoretical center of each bit period (samples 7, 8, and 9, with majority voting).
- Receive Shift Register (RSR): Reassembles serial data into parallel format.
Error Detection Mechanisms
Advanced UARTs implement multiple error checks:
- Framing Error: Occurs if the stop bit is not detected at the expected time.
- Parity Error: Mismatch between received and calculated parity (if enabled).
- Overrun Error: Indicates unread data in the receive buffer when new data arrives.
High-speed UARTs (≥1 Mbps) often include FIFO buffers (16–128 bytes deep) to reduce interrupt overhead and prevent overruns.
Clock Synchronization Challenges
Asynchronous operation requires tolerance to clock drift between transmitter and receiver. The maximum permissible drift is derived from:
where N is the number of bits per frame (typically 10–12). For a 115200 bps link with 10-bit frames, this allows ±720 Hz deviation.
2.2 Voltage Levels: TTL, RS-232, and RS-485
Transistor-Transistor Logic (TTL) UART
TTL-level UART signaling operates with binary voltage thresholds defined by transistor saturation and cutoff states. A logic high (1) is typically represented by a voltage between 2.4 V and 5 V, while a logic low (0) falls between 0 V and 0.8 V. The noise margin, derived from the difference between output and input thresholds, ensures robustness against signal degradation:
For 5V TTL, NMH ≈ 0.4V and NML ≈ 0.4V. Modern 3.3V systems scale these thresholds proportionally. TTL’s simplicity makes it ideal for short-range PCB traces and microcontroller communication, but its lack of differential signaling limits noise immunity in longer runs.
RS-232 Voltage Levels
RS-232 inverts TTL’s logic convention and employs higher voltages to combat noise in serial communication. A logic high (0 in RS-232 terms) ranges from -3 V to -15 V, while a logic low (1) spans +3 V to +15 V. The standard defines a minimum slew rate (30 V/µs) to reduce intersymbol interference. The voltage swing enables cable lengths up to 15 meters at 20 kbps, though capacitive effects degrade signal integrity at higher speeds:
RS-232’s asymmetric voltage requirements necessitate charge pumps or dual-supply line drivers, increasing system complexity compared to TTL.
RS-485 Differential Signaling
RS-485 resolves noise and distance limitations through balanced differential transmission. The standard defines a ±1.5 V minimum differential voltage (VA - VB) with a common-mode range of -7 V to +12 V. The differential receiver rejects common-mode noise by evaluating only the voltage difference between the two lines:
Termination resistors (120 Ω) match the cable’s characteristic impedance to prevent reflections, enabling data rates up to 10 Mbps over 12 meters or 100 kbps at 1.2 km. RS-485’s multidrop capability supports up to 32 unit loads per bus.
Comparative Analysis
- Noise Immunity: RS-485 > RS-232 > TTL due to differential signaling and higher voltage swings.
- Power Efficiency: TTL excels with CMOS-level currents (µA range in idle), while RS-232/485 require active drivers.
- Distance: RS-485 supports kilometers; RS-232 is limited to tens of meters; TTL operates best under 1 meter.
In industrial environments, RS-485 dominates for its robustness, whereas TTL remains prevalent in embedded systems with on-board communication. RS-232 persists in legacy interfaces and debugging consoles despite its declining use.
2.3 Baud Rate and Clock Synchronization
The baud rate in UART communication defines the speed at which data is transmitted, measured in symbols per second (baud). For binary signaling, 1 baud equals 1 bit per second (bps). Accurate baud rate synchronization between transmitter and receiver is critical to prevent data corruption due to clock drift or misalignment.
Baud Rate Calculation
The baud rate is determined by the system clock frequency and the UART's internal divider settings. The relationship is given by:
where fclock is the system clock frequency and UBRR (UART Baud Rate Register) is the divisor value programmed into the UART hardware. For example, with a 16 MHz clock and a desired baud rate of 115200 bps:
Since UBRR must be an integer, rounding to 8 yields an actual baud rate of 104,167 bps (a 9.5% error). To minimize error, some UARTs support fractional baud rate generators.
Clock Synchronization Challenges
Asynchronous UART lacks a dedicated clock line, requiring the receiver to synchronize using:
- Start Bit Detection: A falling edge triggers the receiver's internal clock.
- Oversampling: Typically 16x the baud rate, sampling near the midpoint of each bit for noise immunity.
Even with oversampling, clock drift can cause sampling misalignment. The maximum permissible drift is:
where N is the number of bits per frame (typically 10). For a 1% drift tolerance, the cumulative error must not exceed ±5% over 10 bits.
Advanced Synchronization Techniques
High-speed UARTs (≥1 Mbps) employ:
- Automatic Baud Rate Detection: Measures the width of the start bit to calibrate the receiver clock.
- Digital Phase-Locked Loops (DPLLs): Dynamically adjust sampling points to track transmitter clock variations.
In modern microcontrollers, hardware UART peripherals integrate these features, reducing software overhead. For example, the STM32 USART includes a 24-bit fractional baud rate generator with ±0.008% resolution.
Practical Considerations
Baud rate selection involves trade-offs:
- Higher Rates: Increase throughput but require precise clock sources (e.g., crystal oscillators ±50 ppm).
- Lower Rates: Tolerate higher clock drift but limit data transfer speed.
For long-distance communication, RS-232/485 transceivers often use ±2% tolerance crystals to maintain synchronization across cable-induced jitter.
3. Start Bit, Data Bits, and Stop Bits
3.1 Start Bit, Data Bits, and Stop Bits
The UART protocol frames data transmission using distinct signaling elements: the start bit, data bits, and stop bit(s). These components ensure synchronization and reliable data transfer between asynchronous devices.
Start Bit
The start bit initiates communication by signaling the beginning of a data frame. It is always a logic low (0) level, transitioning from the idle state (logic high or 1). This falling edge serves as a synchronization marker for the receiver, enabling it to detect the incoming data stream's timing. The duration of the start bit equals one baud period, defined as:
For example, at 9600 baud, each bit lasts approximately 104.17 µs. The receiver samples the start bit at its midpoint (typically after 1.5 bit periods) to avoid noise-induced errors during the initial transition.
Data Bits
Immediately following the start bit, the data payload is transmitted as a sequence of 5 to 9 bits, depending on the UART configuration. Most systems use 8 bits (1 byte) for compatibility with standard ASCII encoding. The least significant bit (LSB) is sent first, followed by subsequent bits in ascending order. The voltage levels represent:
- Logic 0: Low voltage (e.g., 0V in TTL)
- Logic 1: High voltage (e.g., 3.3V or 5V)
Data integrity relies on precise timing alignment between the transmitter and receiver. Clock drift must remain within ±4% of the nominal baud rate to prevent sampling errors.
Stop Bit(s)
The stop bit terminates the frame by returning the line to the idle state (logic high). Its duration can be 1, 1.5, or 2 bit periods, with 1 being the most common. The stop bit serves two purposes:
- Provides a guaranteed recovery period before the next start bit.
- Allows minor clock discrepancies between devices to accumulate without causing framing errors.
In systems with high clock tolerance or long cables, two stop bits may be used to enhance reliability. The receiver verifies the stop bit’s logic level; if it is not detected as high, a framing error is flagged.
Timing and Synchronization
The total frame duration depends on the combined lengths of the start bit, data bits, and stop bit(s). For an 8N1 configuration (8 data bits, no parity, 1 stop bit), the frame length is 10 bits. The theoretical maximum data throughput is:
Advanced UART implementations may include fractional baud rate generators to minimize timing errors in high-speed applications (>1 Mbps).
3.2 Parity Bit for Error Detection
The parity bit is a fundamental error-detection mechanism in UART communication, designed to identify single-bit errors during data transmission. It operates by appending an extra bit to each data frame, ensuring the total number of 1s in the frame (including the parity bit) is either even (even parity) or odd (odd parity). The choice between even and odd parity is predetermined by the communicating devices.
Mathematical Foundation
Let a data frame consist of n bits, represented as a binary vector D = [d0, d1, ..., dn-1]. The parity bit p is computed as follows:
For even parity, the sum of all data bits plus the parity bit must be even. Conversely, for odd parity, the sum must be odd. The receiver recalculates the parity upon reception and compares it with the received parity bit to detect errors.
Error Detection Capabilities
The parity bit can detect all single-bit errors, as flipping one bit alters the parity condition. However, it fails to detect even-numbered bit errors (e.g., two flipped bits), as the parity condition remains unchanged. The probability of undetected errors increases with higher bit-error rates (BER).
The effectiveness of parity checking is quantified by the undetected error probability Pu:
where p is the bit-error probability and n+1 is the total number of transmitted bits (including the parity bit). For small p, Pu ≈ (n+1) p2.
Practical Implementation
In hardware, parity generation and checking are implemented using XOR gates. For a data frame D, the parity bit is computed as:
For odd parity, the result is inverted. The receiver performs the same XOR operation on the received data and parity bit, producing a syndrome bit S:
A non-zero S indicates an error. Modern UART controllers integrate parity checking in hardware, flagging errors via status registers or interrupts.
Limitations and Alternatives
While simple, parity checking is insufficient for noisy channels or high-reliability systems. Multi-bit error detection schemes, such as cyclic redundancy checks (CRC) or Hamming codes, are preferred in such cases. However, parity remains widely used in low-speed serial interfaces (e.g., RS-232) due to its minimal overhead.
Framing Errors and How to Handle Them
Framing errors occur when the UART receiver fails to synchronize with the transmitted data frame, leading to misinterpretation of the data bits. These errors arise primarily due to mismatched baud rates, noise-induced signal corruption, or improper start/stop bit detection.
Common Causes of Framing Errors
- Baud Rate Mismatch: If the transmitter and receiver operate at different baud rates, the sampling points drift, causing bit misalignment.
- Noise and Signal Integrity Issues: Electromagnetic interference (EMI) or poor signal grounding can corrupt the start/stop bits.
- Clock Drift: Inaccuracies in the local oscillator frequency can accumulate over long transmissions, shifting sampling instants.
- Improper Voltage Levels: Non-compliant logic levels (e.g., TTL vs. RS-232) may lead to incorrect bit detection.
Mathematical Analysis of Baud Rate Tolerance
The maximum allowable baud rate deviation before a framing error occurs depends on the number of data bits and stop bits. For an N-bit frame with one stop bit, the permissible deviation Δf is given by:
For example, an 8-bit frame (with start and stop bits totaling 10 bits) can tolerate up to ±5% baud rate deviation. Beyond this threshold, the cumulative timing error exceeds half a bit period, leading to incorrect sampling.
Detection and Mitigation Strategies
Hardware-Based Solutions
- Automatic Baud Rate Detection: Some UARTs use synchronization sequences (e.g., 0x55) to dynamically calibrate the receiver's baud rate.
- Oversampling: Sampling each bit at 16x the baud rate (common in modern UARTs) reduces sensitivity to timing errors.
- Error-Correcting Codes (ECC): Advanced implementations use Hamming codes or parity bits to detect and correct bit errors.
Software-Based Solutions
- Framing Error Flags: Most UART peripherals set a status flag (e.g., FE in ARM Cortex-M) when a stop bit is missing or invalid.
- Data Validation: Checksums or CRC fields can identify corrupted frames, triggering retransmission requests.
- Adaptive Timing: Real-time adjustment of sampling points based on historical error patterns.
Case Study: Noise-Induced Framing Errors in Industrial Environments
In a motor control system using RS-485 UART communication, intermittent framing errors were traced to ground loops introducing 20 mV noise spikes. The solution involved:
- Isolating the UART ground plane from motor driver circuits.
- Implementing Schmitt-trigger inputs to improve noise immunity.
- Reducing the baud rate from 1 Mbps to 250 kbps to increase noise margin.
4. Setting Baud Rate and Data Format
4.1 Setting Baud Rate and Data Format
Baud Rate Fundamentals
The baud rate defines the speed of data transmission in a UART system, measured in symbols per second (baud). For binary signaling, baud rate equals bit rate (bits per second). The relationship between the baud rate (B) and the bit time (Tb) is given by:
For reliable communication, both transmitter and receiver must synchronize to the same baud rate. A mismatch of even 2-3% can cause bit errors due to sampling drift. Common standard baud rates include 9600, 19200, 38400, 115200, and 230400 baud, often derived from clock dividers.
Clock Divider Calculation
Microcontrollers generate baud rates by dividing their system clock (fclk). For a target baud rate B, the divider value N is calculated as:
where k depends on the UART mode (typically 16 for asynchronous mode). For example, an STM32F4 (fclk = 84 MHz) targeting 115200 baud requires:
The nearest integer (N = 45) yields an actual baud rate of 116666 baud (1.27% error), which is within the tolerable 2-3% margin.
Data Frame Configuration
A UART data frame consists of:
- Start bit (1 logic-low bit)
- Data bits (5–9 bits, typically 8)
- Parity bit (optional, even/odd/none)
- Stop bits (1, 1.5, or 2 logic-high bits)
The total frame length L in bits is:
where D = data bits, P = parity bits (0 or 1), and S = stop bits. For an 8N1 configuration (8 data bits, no parity, 1 stop bit), L = 10 bits. The effective data throughput R (in bytes/sec) is then:
Practical Considerations
High baud rates (>1 Mbps) require precise clock sources (e.g., crystal oscillators) due to tighter tolerance requirements. For long-distance communication, lower baud rates (≤115200) are preferred to mitigate signal integrity issues. Some UART implementations support auto-baud detection, where the receiver synchronizes to an incoming start pulse.
Register-Level Configuration
On ARM Cortex-M microcontrollers, baud rate and frame format are configured via the USART_BRR (Baud Rate Register) and USART_CR1 (Control Register 1). For example, to set 115200 baud with 8N1 format:
// STM32 HAL example
UART_HandleTypeDef huart1;
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
HAL_UART_Init(&huart1);
4.2 Flow Control: Hardware and Software Methods
Hardware Flow Control (RTS/CTS)
Hardware flow control in UART systems employs dedicated control lines - Request to Send (RTS) and Clear to Send (CTS) - to manage data transmission between devices. The RTS/CTS handshake follows this sequence:
- The transmitting device asserts RTS when ready to send data
- The receiving device asserts CTS when ready to receive
- Data transmission begins only when both signals are active
- CTS is de-asserted when the receiver's buffer approaches capacity
The timing relationship between these signals is critical. For a system with baud rate B and buffer size N, the minimum response time tresponse must satisfy:
Modern implementations often use Schmitt trigger inputs for noise immunity, with typical voltage thresholds of 0.8V (low-to-high) and 2.0V (high-to-low) for 3.3V systems.
Software Flow Control (XON/XOFF)
Software flow control uses in-band signaling with special ASCII characters (XON: 0x11, XOFF: 0x13) when hardware lines are unavailable. The protocol operates as follows:
- Receiver sends XOFF when buffer reaches 75-80% capacity
- Transmitter pauses until receiving XON
- Receiver sends XON when buffer falls below 20-25% capacity
The minimum buffer size Nmin for reliable operation depends on the round-trip latency tlatency:
Common pitfalls include character echo causing false triggers and binary data corruption when payload contains XON/XOFF bytes. Advanced implementations use escape sequences or byte stuffing to mitigate this.
Comparative Analysis
The choice between hardware and software methods involves several tradeoffs:
Parameter | Hardware | Software |
---|---|---|
Latency | ~1 bit time | ~10-100 bit times |
Reliability | High (dedicated lines) | Medium (in-band signaling) |
Wiring | 4-wire (TX,RX,RTS,CTS) | 2-wire (TX,RX) |
Maximum Baud | >10 Mbps | <1 Mbps |
Advanced Techniques
Modern systems often implement hybrid approaches:
- Adaptive Thresholding: Dynamically adjusts XON/XOFF thresholds based on buffer usage patterns
- Window-Based Flow Control: Uses multiple XON/XOFF levels for finer granularity
- Predictive Pausing: Analyzes traffic patterns to anticipate buffer needs
For high-reliability systems, the error probability Pe can be modeled as:
where BER is the bit error rate and L represents the respective message lengths.
4.3 Common Configuration Pitfalls
Baud Rate Mismatch
A critical yet frequently overlooked pitfall is baud rate mismatch between the transmitter and receiver. Even a slight deviation—caused by clock inaccuracies or improper configuration—leads to bit sampling errors. The maximum permissible baud rate error is given by:
For a standard 8N1 frame (10 bits), the allowable error reduces to ±5%. Crystal oscillators with ±50 ppm tolerance may suffice for lower baud rates, but higher speeds (e.g., 1 Mbps+) demand temperature-compensated oscillators (TCXO) or phase-locked loops (PLLs).
Frame Desynchronization Due to Noise
Electromagnetic interference (EMI) or ground loops can corrupt start/stop bits, causing the receiver to misalign subsequent data. A glitch filter or Schmitt trigger input mitigates this by rejecting pulses shorter than 0.5 bit periods. The noise margin is quantified as:
where \(V_{\text{IH}}\) and \(V_{\text{IL}}\) are the input high/low voltage thresholds. RS-232’s wide voltage swings (±3 V to ±15 V) inherently tolerate more noise than 3.3V TTL UART.
Buffer Overflows and Flow Control Neglect
Without hardware flow control (RTS/CTS) or software flow control (XON/XOFF), high-speed UART links risk overrunning receiver buffers. The critical buffer size \(B_{\text{min}}\) to prevent overflow at baud rate \(R\) with processing latency \(L\) is:
For example, a 115200 baud system with 10 ms latency requires a 144-byte buffer. Neglecting this leads to silent data truncation—a fault often misdiagnosed as peripheral hardware failure.
Clock Domain Crossing Issues
In FPGA implementations, metastability arises when UART signals traverse asynchronous clock domains. Dual-flop synchronizers are insufficient for multi-bit signals like parallelized UART data. Instead, use gray coding or FIFO buffers with handshake protocols. The mean time between failures (MTBF) for a synchronizer is:
where \(t_r\) is the resolution time, \(\tau\) the flip-flop time constant, and \(\alpha\) the activity factor.
Parity Bit Misconfiguration
Enabling parity without verifying the receiver’s matching setting causes undetected errors. Odd parity is preferable for systems with dominant 0s (e.g., idle-high lines), as it ensures at least one transition per byte. The undetected error probability \(P_{\text{undetected}}\) for single-bit flips is:
For 8-bit data with parity, this equals \(9/512 \approx 1.76\%\)—unacceptably high for medical or aerospace applications, necessitating CRC checks.
Voltage Level Incompatibility
Mixing 5V TTL and 3.3V CMOS UARTs without level shifters induces input threshold violation. A 3.3V output (\(V_{\text{OH}} = 2.4V\)) may fail to meet a 5V device’s \(V_{\text{IH}} = 2.8V\) requirement. The solution involves either:
- Bidirectional voltage translators (e.g., TXB0104)
- Optocouplers for galvanic isolation
- Series resistors for current limiting
5. Interfacing UART with Microcontrollers
5.1 Interfacing UART with Microcontrollers
Hardware-Level UART Communication
UART operates asynchronously, requiring precise timing synchronization between transmitter and receiver. The protocol defines:
- Start bit (1 logic low pulse)
- Data frame (5-9 bits, LSB first)
- Parity bit (optional error checking)
- Stop bit(s) (1-2 logic high pulses)
Where BRD is the baud rate divisor, typically a 16-bit value programmed into the microcontroller's UART registers. Modern microcontrollers often include fractional baud rate generators for improved accuracy.
Register Configuration
Key registers for UART initialization on ARM Cortex-M devices:
// STM32 UART initialization example
void UART_Init(void) {
// 1. Enable clock to USART2 and GPIOA
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
// 2. Configure PA2 (TX) and PA3 (RX) in alternate function mode
GPIOA->MODER &= ~(GPIO_MODER_MODER2 | GPIO_MODER_MODER3);
GPIOA->MODER |= (2U << GPIO_MODER_MODER2_Pos) | (2U << GPIO_MODER_MODER3_Pos);
// 3. Set baud rate (for 115200 @ 16MHz)
USART2->BRR = 0x008B; // 16MHz/(16*115200) = 8.68 → 0x008B
// 4. Enable transmitter, receiver, and UART
USART2->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
}
Interrupt-Driven Operation
For efficient data handling, UART peripherals generate interrupts for:
- Transmit Data Register Empty (TXE)
- Receive Data Register Not Empty (RXNE)
- Parity/Frame/Overrun errors
The interrupt service routine typically implements a circular buffer:
#define BUF_SIZE 256
volatile uint8_t rx_buf[BUF_SIZE];
volatile uint16_t rx_head = 0, rx_tail = 0;
void USART2_IRQHandler(void) {
if(USART2->SR & USART_SR_RXNE) {
uint8_t data = USART2->DR;
rx_buf[rx_head++] = data;
if(rx_head >= BUF_SIZE) rx_head = 0;
}
}
Signal Integrity Considerations
For reliable communication over longer distances (>1m), RS-232 or RS-485 transceivers are required. Key parameters:
Termination resistors (typically 120Ω for RS-485) must match the cable characteristic impedance to prevent reflections. For high-speed UART (>1Mbps), transmission line effects become significant:
Advanced Techniques
Modern microcontrollers implement hardware flow control (RTS/CTS) and DMA integration. The DMA controller can automatically transfer data between UART and memory without CPU intervention, reducing interrupt overhead.
5.2 Debugging UART Communication Issues
UART communication failures often stem from subtle mismatches in configuration, signal integrity problems, or timing errors. Advanced debugging requires systematic isolation of potential failure points.
Signal Integrity and Voltage Levels
UART relies on precise voltage thresholds for logic levels. A common issue arises when transmitter and receiver operate at incompatible voltage standards (e.g., 3.3V vs. 5V). Verify signal levels with an oscilloscope:
- Idle state: Should match the line's nominal voltage (e.g., 3.3V for logic high).
- Start bit: A clean transition to 0V within 0.5 bit periods.
- Noise: Ringing or overshoot exceeding 20% of VDD may cause bit errors.
For mixed-voltage systems, use level shifters or series resistors to limit current. The maximum allowable voltage mismatch is given by:
Baud Rate Mismatch
Even small baud rate discrepancies accumulate timing errors over frames. The permissible error depends on the UART's sampling strategy. For 16× oversampling (common in modern UARTs), the maximum tolerable error is:
Measure actual baud rates using:
- Oscilloscope: Time 10 bit periods, calculate Tbit = t10/9.
- Logic analyzer: Statistical analysis of bit transitions.
Framing Errors
Framing issues manifest as stop bit violations or parity errors. Check:
- Data length: Both devices must agree on 5–9 bits/character.
- Stop bits: 1, 1.5, or 2 must match.
- Parity: Odd/even/none settings alignment.
Modern UARTs often provide status registers with error flags. For example, the 16550D UART reports:
uint8_t lsr = inb(UART_LSR_REG);
if (lsr & LSR_FE) // Framing error
handle_error();
if (lsr & LSR_PE) // Parity error
recalculate_parity();
Hardware Flow Control Issues
When using RTS/CTS flow control:
- Verify signal polarity (active-low vs. active-high).
- Check for deadlocks where both devices assert RTS simultaneously.
- Measure CTS response time—should deassert within 3 bit periods.
The flow control timing constraint is:
Electromagnetic Interference (EMI)
Long UART lines (>0.5m) are susceptible to EMI. Mitigation strategies include:
- Twisted-pair wiring with impedance matching (120Ω for RS-422).
- Low-pass filtering on RX lines: fcutoff = 0.35/trise.
- Common-mode chokes for differential UART variants (RS-485).
For critical applications, calculate the signal-to-noise ratio (SNR) requirement:
5.3 Real-world Applications of UART
Embedded Systems and Microcontrollers
UART remains a cornerstone in embedded systems due to its simplicity and low overhead. Microcontrollers such as ARM Cortex-M, AVR, and PIC integrate hardware UART peripherals for serial communication with sensors, displays, and other peripherals. For instance, GPS modules like the NEO-6M output NMEA sentences via UART at standard baud rates (9600, 38400, or 115200 bps). The lack of clock synchronization makes UART ideal for battery-powered devices where minimizing power consumption is critical.
Industrial Automation and Control Systems
In industrial settings, UART interfaces with Programmable Logic Controllers (PLCs) and Human-Machine Interfaces (HMIs) to transmit control signals and sensor data. RS-232 and RS-485 (which build upon UART) enable long-distance communication in noisy environments. For example, Modbus RTU, a widely used industrial protocol, operates over UART with RS-485, supporting multi-drop configurations with addresses for up to 247 devices.
Debugging and System Logging
UART serves as a primary debug interface for embedded systems. Many System-on-Chip (SoC) designs, including FPGAs and ASICs, implement UART ports to output diagnostic data during development. Linux-based embedded systems often route kernel logs (printk
output) to a UART console, allowing real-time monitoring without additional hardware. The baud rate must match between transmitter and receiver to avoid framing errors, governed by the equation:
where UBRR is the UART Baud Rate Register value and fclock is the system clock frequency.
Wireless Communication Modules
Bluetooth (e.g., HC-05) and Wi-Fi modules (e.g., ESP8266) often use UART for configuration and data transfer. The ESP8266, for instance, accepts AT commands via UART to establish TCP/IP connections. Wireless protocols like Zigbee (using XBee modules) also rely on UART for point-to-point or mesh networking, with packetization handled at higher layers.
Automotive and Vehicular Networks
While CAN bus dominates automotive networks, UART is still used for low-speed auxiliary systems like infotainment or diagnostics. On-Board Diagnostics (OBD-II) interfaces sometimes include UART alongside CAN to communicate with legacy tools. The UART frame structure—start bit, 5–9 data bits, optional parity, and stop bits—ensures compatibility with diverse legacy systems.
Consumer Electronics and IoT
UART enables communication between System-on-Modules (SoMs) like Raspberry Pi and peripheral ICs (e.g., RFID readers, thermal printers). In IoT edge devices, UART bridges microcontrollers with cellular modems (e.g., SIM800L) for GSM/GPRS connectivity. Flow control (RTS/CTS) is often implemented to prevent buffer overflows in these applications.
Retro Computing and Legacy Hardware
Older computers (e.g., IBM PC) used UART chips like the 16550 for serial ports. Modern retro-computing projects emulate these interfaces using USB-to-UART converters (e.g., FT232RL). The UART’s asynchronous nature allows compatibility with vintage hardware without clock recovery circuits, though signal levels may require level shifters (e.g., MAX232 for RS-232 voltage conversion).
Medical and Laboratory Equipment
Medical devices such as blood glucose meters and ECG monitors often export data via UART to centralized logging systems. The protocol’s simplicity ensures reliability in critical applications, with error detection handled through parity bits or software-level checksums. For example, a common UART-based health sensor frame might include:
6. Recommended Books and Articles
6.1 Recommended Books and Articles
- 1.6 Module: Universal Asynchronous Receiver Transmitter (UART) — 1.6 Module: Universal Asynchronous Receiver Transmitter (UART) 1.6.1 UART TXDE Signal May Go Low Before the STOP Bit Has Been Entirely Transmitted. ... 1.6 Module: Universal Asynchronous Receiver Transmitter (UART) The online versions of the documents are provided as a courtesy. Verify all content and data in the device's PDF documentation ...
- PDF Universal Asynchronous Receiver/Transmitter (UART) for KeyStone Devices UG — Universal Asynchronous Receiver/Transmitter (UART) Literature Number: SPRUGP1 November 2010 User Guide. ... Universal Asynchronous Receiver/Transmitter (UART) peripheral. 1.1 "Purpose of the Peripheral" on page 1-2 1.2 "Features" on page 1-2 1.3 "Functional Block Diagram" on page 1-3
- Universal Asynchronous Receiver and Transmitter (UART) — Download book PDF. ... There are several serial communication protocols like UART (Universal Asynchronous Receiver and Transmitter), SPI (Serial Peripheral Interface), or I2C (Inter-Integrated Circuit). ... (2018). Universal Asynchronous Receiver and Transmitter (UART). In: Getting Started with Tiva ARM Cortex M4 Microcontrollers. Springer, New ...
- PDF UART: Universal Asynchronous Receiver & Transmitter — UART: Universal Asynchronous Receiver & Transmitter Lecture 2a. Based on the Atmega328P datasheet and material from Bruce Land's video lectures at Cornel Copied from Lecture 2a, ECE3411 -Fall 2015, by Marten van Dijk and Syed Kamran Haider. ... FILE uart_str = FDEV_SETUP_STREAM ...
- PDF Universal Asynchronous Receiver Transmitter (UART) - Microchip Technology — The Universal Asynchronous Receiver Transmitter (UART) module is one of the serial I/O modules available in the dsPIC33 and PIC24 device families. The UART is a full-duplex, asynchronous communication channel that communicates with peripheral devices and personal computers, using protocols such as RS-232, RS-485, LIN/J2602 and IrDA®. The ...
- Universal Asynchronous Receiver/Transmitter - studylib.net — The information in this document assumes familiarity with these standards. 1-4 KeyStone Architecture Universal Asynchronous Receiver/Transmitter (UART) User Guide SPRUGP1—November 2010 Submit Documentation Feedback Chapter 2 Architecture The following sections give an overview of the main components and features of the Universal Asynchronous ...
- PDF Getting Started with Universal Synchronous and Asynchronous Receiver ... — Getting Started with Universal Synchronous and Asynchronous Receiver and Transmitter (USART) Introduction Author: Alexandru Niculae, Microchip Technology Inc. The purpose of this document is to describe step-by-step how to configure the USART peripheral on megaAVR® 0-series, tinyAVR® 0- and 1-series, and AVR® DA devices. While this is a ...
- PDF AT07896: Universal Asynchronous Receiver Transceiver (UART) ASF ... — AT07896: Universal Asynchronous Receiver Transceiver (UART) [APPLICATION NOTE] 42299A-MCU-05/2014 7 3. Special Considerations This device provides a simple two pin (Recieve and Transmit) serial connection. For more sophisticated usage requiring hardware handshaking etc. consider using a USART or making use of GPIO pins and additional software.
- UART - Specification by Texas Instruments — IX-2 KeyStone Architecture Universal Asynchronous Receiver/Transmitter (UART) User Guide SPRUGP1—November 2010 Submit Documentation Feedback IMPORTANT NOTICE Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services ...
- PDF Serial Communication Protocols and Standards — Contents Preface xix ListofFigures xxiii ListofTables xxxi ListofAbbreviations xxxv 1 Serial Communication 1 1.1 Introduction ...
6.2 Online Resources and Tutorials
- PDF AT07896: Universal Asynchronous Receiver Transceiver (UART) ASF ... — AT07896: Universal Asynchronous Receiver Transceiver (UART) [APPLICATION NOTE] 42299A-MCU-05/2014 6 2. Module Overview The Universal Asynchronous Receiver Transmitter (UART) features a two-pin UART that can be used for communication and trace purposes and offers an ideal medium for in-situ programming solutions. Moreover, the
- Universal Asynchronous Receiver and Transmitter (UART) — Universal Asynchronous Receiver and Transmitter (UART) Chapter; First Online: 17 October 2017; ... Division of Electronics and Communications Engineering, Netaji Subhas Institute of Technology, New Delhi, India ... D.V., Gupta, S. (2018). Universal Asynchronous Receiver and Transmitter (UART). In: Getting Started with Tiva ARM Cortex M4 ...
- PDF Universal Asynchronous Receiver Transmitter (UART) - Microchip Technology — The Universal Asynchronous Receiver Transmitter (UART) module is one of the serial I/O modules available in the dsPIC33 and PIC24 device families. The UART is a full-duplex, asynchronous communication channel that communicates with peripheral devices and personal computers, using protocols such as RS-232, RS-485, LIN/J2602 and IrDA®. The ...
- PDF Universal Asynchronous Receiver/Transmitter (UART) for KeyStone Devices UG — SPRUGP1—November 2010 KeyStone Architecture Universal Asynchronous Receiver/Transmitter (UART) User Guide 1-1 Submit Documentation Feedback Chapter 1 Introduction The following sections provide an overview of the main components and features of the Universal Asynchronous Receiver/Transmitter (UART) peripheral.
- PDF AN2853: Using Universal Asynchronous Receiver Transmitter (UART) eTPU ... — Using the Universal Asynchronous Receiver Transmitter (UART) eTPU Function, Rev. 0.1 UART Overview 2 Freescale Semiconductor etc. However, any channel can be a ssigned as the transmit channel, a nd any other channel can be assigned as the receive channel. Standard ba ud rates and non-standard baud rates, in addition to parity checking can be ...
- Multiprotocol Universal Asynchronous Receiver Transmitter (UART) Module — The Universal Asynchronous Receiver Transmitter (UART) is a flexible serial communication peripheral used to interface PIC® microcontrollers with other equipment, including computers and peripherals. The UART is a full-duplex, asynchronous communication channel that can be used to implement protocols, such as RS-232 and RS-485.
- PDF Software UART using ST7LITE0 12-bit autoreload timer - STMicroelectronics — This application note describes a software implementation of a Universal Asynchronous Receiver/Transmitter (UART). This can be used on devices with no on-chip SCI peripheral. In this example, a software UART is implemented for the ST7LITE0, using the 12-bit Autoreload timer and two I/O ports for asynchronous receive and transmit. The UART
- PDF Getting Started with Universal Synchronous and Asynchronous Receiver ... — Getting Started with Universal Synchronous and Asynchronous Receiver and Transmitter (USART) Introduction Author: Alexandru Niculae, Microchip Technology Inc. The purpose of this document is to describe step-by-step how to configure the USART peripheral on megaAVR® 0-series, tinyAVR® 0- and 1-series, and AVR® DA devices. While this is a ...
- 28 EUSART - Enhanced Universal Synchronous Asynchronous Receiver ... — The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module is a serial I/O communications peripheral. It contains all the clock generators, Shift registers and data buffers necessary to perform an input or output serial data transfer independent of device program execution.
- Getting Started with Universal Synchronous and Asynchronous Receiver ... — The online versions of the documents are provided as a courtesy. Verify all content and data in the device's PDF documentation found on the device product page.
6.3 Datasheets and Technical Manuals
- 34.6.2.6.3 Asynchronous Data Reception - onlinedocs.microchip.com — 34 Universal Synchronous and Asynchronous Receiver-Transmitter (SERCOM USART) 34.6 Functional Description. 34.6.2 Basic Operation. ... 34 Universal Synchronous and Asynchronous Receiver-Transmitter (SERCOM USART) 34.1 Overview. 34.2 USART Features. ... 34.6.2.6.3 Asynchronous Data Reception. 34.6.2.6.4 Asynchronous Operational Range.
- Universal Asynchronous Receiver Transmitter (UART) Protocol — UART means Universal Asynchronous Receiver Transmitter Protocol. UART is used for serial communication from the name itself we can understand the functions of UART, where U stands for Universal which means this protocol can be applied to any transmitter and receiver, and A is for Asynchronous which means one cannot use clock signal for communication of data and R and T refers to Receiver and ...
- PDF SC16C750 Universal Asynchronous Receiver/Transmitter (UART) with 64 ... — The SC16C750 is a Universal Asynchronous Receiver and Transmitter (UART) used for serial data communications. Its principal function is to convert parallel data into serial data, and vice versa. The UART can handle serial data rates up to 3 Mbits/s. The SC16C750 is pin compatible with the TL16C750 and it will power-up to be
- PDF Multiprotocol Universal Asynchronous Receiver Transmitter (UART) Module — The Universal Asynchronous Receiver Transmitter (UART) is a flexible serial communication peripheral used to interface PIC® microcontrollers with other equipment, including computers and peripherals. The UART is a full-duplex, asynchronous communication channel that can be used to implement protocols, such as RS-232 and RS-485.
- Universal Asynchronous Receiver and Transmitter Peripherals — What Is Universal Asynchronous Receiver and Transmitter (UART)? UART, also known as Serial Communications Interface (SCI), is a simple, single-host serial protocol. This protocol is asynchronous, which means there are no shared clock lines between host and target devices.
- PDF AT07896: Universal Asynchronous Receiver Transceiver (UART) ASF ... — AT07896: Universal Asynchronous Receiver Transceiver (UART) [APPLICATION NOTE] 42299A-MCU-05/2014 7 3. Special Considerations This device provides a simple two pin (Recieve and Transmit) serial connection. For more sophisticated usage requiring hardware handshaking etc. consider using a USART or making use of GPIO pins and additional software.
- Universal Asynchronous Receiver-Transmitter (UART) - Arduino Docs — The key components of UART include the transmitter, receiver, and baud rate. The transmitter collects data from a source, formats it into serial bits, and sends it via a TX (Transmit) pin. The receiver receives it via a RX (Receive) pin, processes incoming serial data and converts it into parallel data for the host system.
- PDF PC16550D Universal Asynchronous Receiver/Transmitter With FIFOs - Digi-Key — the receiver. DCD 38 42 I NOTE Whenever the DCD bit of the MODEM Status Register changes state, an interrupt is generated if the MODEM Status Interrupt is enabled. Driver Disable. This goes low whenever the CPU is reading data from the UART. It can disable DDIS 23 26 O or control the direction of a data bus transceiver between the CPU and the UART.
- PDF Universal Asynchronous Receiver Transmitter (UART) - Microchip Technology — available on all devices. Refer to the "Universal Asynchronous Receiver Transmitter (UART)" chapter of the specific device data sheet for availability.) • Fully integrated Baud Rate Generator (BRG) with 16-bit prescaler • Baud rates up to 17.5 Mbps • Four-deep First-In First-Out (FIFO) transmit data buffer • Four-deep FIFO receive ...
- EUSART/AUSART: Enhanced-Addressable-Universal-Asynchronous-Receiver ... — The Enhanced/Addressable Universal Asynchronous Receiver Transceiver (EUSART/AUSART) is a peripheral for handling serial I/O communications. It contains all the clock generators, shift registers, and data buffers necessary to perform an input or output serial data transfer independent of the main program execution.