UART troubleshooting: fast diagnosis summary
Garbage characters, framing errors, and missing UART data often result from baud rate mismatches, incorrect UART settings, logic-level incompatibility, or electrical noise. Measure the TX bit period, verify UART configuration on both devices, check signal voltage levels, and review firmware error flags to identify the cause.
| Symptom | Most Likely Cause | First Diagnostic Step | Fix |
|---|---|---|---|
| Garbage characters / gibberish RX | Baud rate mismatch | Measure TX bit period on oscilloscope | Match baud rates; use crystal clock source |
| Framing error flag set on every byte | Stop bit not detected (baud/parity mismatch) | Compare baud rate, data bits, parity, stop bits both ends | Align UART config: 8N1 / 8E1 / 9600 etc. |
| All bytes received as 0x00 or 0xFF | Logic level mismatch or inverted signal | Probe RX pin with oscilloscope, check idle HIGH | Add level shifter or fix voltage domain |
| Intermittent errors — worsens at temperature | Internal oscillator (HSI/RC) drift | Replace with crystal-clocked UART, monitor error rate vs temp | Switch to external crystal or TCXO clock source |
| Overrun error (ORE) flag in firmware | RX buffer overflow — bytes not read fast enough | Check ISR latency, DMA config, FIFO depth | Use DMA RX, increase buffer, reduce baud rate |
| RX works at 9600, fails at 115200+ | BRR rounding error at high baud; signal integrity | Verify BRR divisor gives <2% error; probe eye diagram | Use crystal, reduce cable length, reduce baud |
| First byte lost on every transmission | Missing or inadequate RX enable time / FIFO flush | Check hardware flow control timing, check FIFO flush sequence | Assert RTS/DE before first byte; flush FIFO on init |
| TX sends nothing | TX pin not connected; GPIO not assigned to UART AF | Probe TX pin, verify AF mapping in firmware | Remap GPIO alternate function; check PCB net |
UART Frame Structure: What Must Agree Between TX and RX
UART (Universal Asynchronous Receiver-Transmitter) is a full-duplex serial protocol with no shared clock line. Synchronization is achieved entirely through agreed-upon timing: both ends must independently generate the same bit period (the reciprocal of the baud rate) from their own clock sources. A single byte is transmitted as a frame consisting of a start bit, data bits, an optional parity bit, and one or two stop bits. The receiver waits for the falling edge of the start bit, then samples the subsequent bits at intervals of one bit period, beginning 1.5 bit periods after the start-bit edge (to sample near the centre of each bit).
Every parameter of the frame must be identical on the transmitter and receiver. A mismatch in any single parameter will corrupt received data, generate error flags, or produce no reception at all. The parameters are: baud rate (bits per second), data bits (5, 6, 7, or 8 — almost universally 8 in modern systems), parity (None, Even, or Odd), and stop bits (1 or 2). The shorthand 8N1 means 8 data bits, No parity, 1 stop bit and is by far the most common configuration in embedded systems. Any deviation from this default must be explicitly configured identically on both ends.

| ⚡ Quick fact — UART idle line is logic-HIGH |
|---|
| An idle UART TX or RX line sits at logic-HIGH (VCC level). The start bit is the first LOW, which the receiver detects as the beginning of a frame. If the line is stuck LOW (logic-0 at idle), the receiver will continuously try to decode a start bit and will produce a constant stream of framing errors. This is the first thing to check when RX produces garbage immediately after power-up: probe the TX output of the transmitting device at idle and confirm it is at VCC. |
Baud Rate Accuracy: Clock Sources, Tolerance, and BRR Calculation
Because UART has no shared clock, the accuracy of data reception depends entirely on the accuracy of the baud rate generators at both ends. If the transmitter sends bits at 115200 baud and the receiver is running at 112000 baud (a 2.9% deficit), the sampling point drifts progressively through the frame. By the eighth data bit, the receiver is sampling approximately 24% of one bit period too late, placing the sample point dangerously close to the transition to the stop bit. At worst, the last bit is misread or the stop bit sample falls into the previous data bit’s time slot, causing a framing error.
The Baud Rate Tolerance Derivation
The tolerable mismatch E (expressed as a percentage of nominal baud rate) can be derived from first principles. The receiver samples the last data bit at 8.5 bit periods from the start-bit falling edge (for 8N1). Each bit period, the receiver’s clock contributes an error of E% of one bit period. By the final bit, cumulative drift is 8.5 × E% of one bit period. For the sample to remain within the valid mid-bit window, this drift must not exceed approximately 30% of one bit period (the remaining margin after accounting for start-bit sampling imprecision):
8.5 × E / 100 < 0.30 ⇒ E < 3.5% per device
However, both the transmitter and receiver clocks have independent errors that add in the worst case. If both have errors of equal magnitude but opposite sign, the total effective mismatch is 2E%. The combined limit becomes approximately 2% total mismatch — 1% per device. This is the basis for the commonly cited rule that UART requires baud rate accuracy better than 2% combined between the two endpoints. With parity enabled (8E1 or 8O1), one additional bit is sampled, tightening the tolerance further to approximately 1.5% per device.
Clock Source Selection and Its Impact
The achievable baud rate accuracy is determined by the clock source driving the UART peripheral. The table below summarises the accuracy of common clock sources used in microcontrollers.
| Clock Source | Accuracy (25°C) | Accuracy (over temp) | Suitable for UART? | Notes |
|---|---|---|---|---|
| External crystal (HSE) | ±20–50 ppm | ±50–100 ppm | Yes — preferred | Best accuracy; mandatory for USB-combined designs |
| TCXO (temperature-compensated) | ±0.5–2 ppm | ±2–5 ppm | Yes — excellent | Required for precision timing or narrow-band RF |
| Internal RC (HSI) — STM32 calibrated | ±1% | ±2–3% over temp | Marginal — risky above 115200 | Trim at 25°C only; degrades with temperature |
| Internal RC (ESP32) | Varies ±5% uncalibrated | ±10% worst case | No — unreliable alone | Use external XTAL for UART; auto-baud helps |
| RP2040 ROSC | ±50% untrimmed | Unusable | No | 12 MHz XOSC required; ROSC for non-timing tasks only |
| LPUART + LSE (32.768 kHz crystal) | ±20 ppm | ±50 ppm | Yes — for low baud rates | 256x oversampling; ideal for 9600 baud in sleep modes |
| ⚠️ Common failure scenario — changing the system clock without recalculating BRR |
|---|
| On STM32 and similar microcontrollers, the UART baud rate register (BRR or USARTDIV) is computed as: BRR = fPCLK / (oversampling_ratio × baud_rate). If the peripheral clock (fPCLK) changes — because the PLL configuration was updated, or the APB prescaler was changed, or the HSI/HSE source was switched — the BRR value is now wrong. The UART hardware will not report any error; it will simply run at the wrong baud rate. The HAL_UART_Init() function returns HAL_OK even when the requested baud rate cannot be achieved exactly. Always call HAL_UART_Init() after any clock tree modification. When debugging baud rate issues after a firmware update, the first question to ask is: did the system clock configuration change? |
BRR Rounding Error at High Baud Rates
The baud rate register holds an integer (or integer plus fraction, depending on the peripheral). The actual baud rate is f_PCLK / (N × BRR_value), where N is the oversampling ratio (16 or 8). If the division is not exact, the BRR must be rounded, introducing a fixed error. This error is proportionally larger at higher baud rates because the BRR value is smaller and the rounding error is a larger fraction of it.
For example, on a 42 MHz APB1 clock at 115200 baud with 16x oversampling: BRR = 42,000,000 / (16 × 115200) = 22.786, rounded to 23, giving an actual baud rate of 42,000,000 / (16 × 23) = 114,130 baud — an error of 0.93%, which is acceptable. At 921600 baud with the same clock: BRR = 42,000,000 / (16 × 921600) = 2.848, rounded to 3, giving 42,000,000 / 48 = 875,000 baud — an error of 5.1%, which exceeds the 3.5% single-device limit and will cause framing errors with another device at exactly 921600 baud.
The diagnostic: if a design works reliably at 9600 baud but not at 115200 or higher, BRR rounding error is a primary suspect alongside signal integrity. Calculate the exact BRR value and the resulting actual baud rate from the datasheet formula before assuming a hardware fault.
UART Error Types: Flags, Causes, and Firmware Handling
Modern UART peripherals maintain status flags that identify four distinct error conditions. Each flag corresponds to a different failure mechanism and requires a different diagnostic and software response. Critically, most UART peripherals hold received data in the receive data register (RDR) even when an error flag is set. The firmware must read the status register before reading RDR to know whether the received byte is reliable.
| Error Type | UART Flag (typical) | Cause | Effect on RX data | Firmware Detection |
|---|---|---|---|---|
| Framing Error (FE) | FE / FER / FERR | Stop bit sampled as logic-0 (baud mismatch, noise, break signal) | Byte discarded; garbage byte may appear in FIFO | Read status register before RDR; clear FE before re-enabling RX |
| Overrun Error (ORE) | ORE / OERR | New byte arrived before firmware/DMA read previous byte from RDR | Previous byte overwritten and lost; ORE set | Use DMA circular buffer or large FIFO; check ISR latency |
| Parity Error (PE) | PE / PERR | Received parity bit does not match computed parity of data bits | Byte placed in FIFO but PE flag set; value may be corrupt | Check PE after each byte; retransmit on detected PE |
| Noise Error (NE) | NE / NERR | Majority vote samples disagree during 16x oversampling | Byte may be incorrect; NE flag set alongside FE or PE | Monitor NE rate; indicates signal integrity problem |
| Break Condition | LBD / BRK | RX line held LOW for > one full frame duration | All-zeros byte received; FE also set | Distinguish break from framing error by duration; used in LIN protocol |
Framing Error (FE): The Most Common Error Flag
A framing error occurs when the UART receiver detects a logic-LOW signal instead of the expected logic-HIGH stop bit. The received byte may be incorrect or unreliable. After detecting the error, the receiver resets its bit counter and waits for the next start bit.
The most common causes are baud rate mismatch, incorrect data/parity/stop-bit settings, and electrical noise. For example, if the transmitter uses 8N1 but the receiver uses 7E1, the receiver checks for the stop bit at the wrong position. Repeated framing errors usually indicate a configuration mismatch, while intermittent errors may point to signal integrity problems.
| 🚨 Critical — do not read RDR without checking FE first |
|---|
| On STM32 UART peripherals (and many others), reading the status register (ISR/SR) followed by reading the receive data register (RDR/DR) atomically clears the FE flag. If your firmware reads RDR without first checking the FE flag, it will silently discard the error information. The correct sequence in an interrupt handler is: (1) read SR/ISR to get all error flags, (2) check each flag individually, (3) read RDR/DR to clear RXNE and get the data byte, (4) handle the error (log, discard, retransmit). On STM32 HAL, the HAL_UART_ErrorCallback() fires only if error interrupt enable bits (FEIE, OREIE) are set in the CR3 register. |
Overrun Error (ORE): A Firmware Timing Problem
An overrun error occurs when the UART shift register completes assembly of a new byte while the previous byte has not been read from RDR by firmware. The new byte cannot be transferred to RDR, so it is discarded and the ORE flag is set. The previous byte in RDR is preserved. ORE is not an electrical or configuration problem; it is a software throughput problem. It indicates that the gap between consecutive received bytes (determined by the baud rate) is shorter than the time firmware takes to service the UART receive event and read RDR.
At 115200 baud with 8N1 framing, one byte occupies 86.8 μs. If the interrupt service routine takes longer than 86.8 μs from the time RXNE fires to the time RDR is read, and two bytes arrive back-to-back, an overrun is guaranteed. DMA-based reception (where the DMA controller reads RDR autonomously into a ring buffer without CPU involvement) eliminates ORE at any baud rate that the DMA bus can sustain. When DMA is not available, the interrupt latency and ISR execution time must be verified to be shorter than the inter-byte gap.
Noise Error (NE): Signal Integrity Indicator
A noise error is flagged when the 16x oversampling majority vote samples disagree during a bit period. The receiver takes three samples near the centre of each bit (at positions 7, 8, and 9 of the 16 sample clock cycles per bit). If the three samples are not all the same logic level (e.g., HIGH, LOW, HIGH), the receiver flags a noise error and uses the majority value. The final byte may or may not be correct. When NE is set alongside FE, it indicates that noise affected the stop bit specifically. NE on its own (without FE or PE) suggests that noise is present but not severe enough to cause synchronisation loss. A rising NE flag rate is a leading indicator of a deteriorating connection, long cable without proper termination, or nearby EMI source.
Logic Level Compatibility and Level Shifting
UART logic levels are defined by the I/O voltage of the driving device, not by the UART protocol itself. TTL-level UART (5 V) and LVTTL-level UART (3.3 V) are electrically incompatible with each other and both are incompatible with RS-232 (±3 V to ±15 V swing with inverted logic). Connecting devices across voltage domains without level shifting is a common cause of unreliable UART communication and permanent hardware damage.
| Scenario | TX voltage | RX VIH min | Safe? | Solution |
|---|---|---|---|---|
| 3.3 V MCU → 3.3 V MCU | 3.3 V high | 2.0 V (LVTTL) | Yes | Direct connection; verify VIH spec of target |
| 5 V MCU → 3.3 V MCU (3.3 V not 5V-tolerant) | 5 V high | 2.0 V but max 3.6 V on RX pin | No — pin damage risk | Voltage divider (2:1 ratio) or bidirectional level shifter |
| 5 V MCU → 3.3 V MCU (5V-tolerant RX pin) | 5 V high | 2.0 V; pin tolerates 5 V | Yes — check datasheet | Direct connection permissible; verify 5V-tolerance in datasheet |
| 3.3 V MCU → 5 V MCU | 3.3 V high | 2.4 V (TTL) or 3.5 V (CMOS) | Marginal for TTL; fail for CMOS | Level shifter or pull-up to 5 V on RX line |
| UART to RS-232 (PC COM port) | ±3.3 V or ±5 V swing | −3 V to +3 V (RS-232 inverted logic) | No — direct connection destroys MCU | MAX232 or SP3232 level converter mandatory |
| MCU 1.8 V I/O → 3.3 V system | 1.8 V high | 2.0 V threshold typically | No — logic-0 may not register | 1.8 V–3.3 V bidirectional translator (TXS0101, BSS138 FET) |
The 5V-to-3.3V Problem in Detail
The most common logic level incompatibility encountered in embedded design is a 5 V AVR, Arduino Uno, or legacy MCU transmitting to a 3.3 V STM32, ESP32, nRF52, or Raspberry Pi module. The 5 V TX output swings to 5 V. The 3.3 V RX pin on the target device has an absolute maximum rating of 3.6 V or 4 V. Applying 5 V to this pin forward-biases the internal ESD protection diode (anode at RX pin, cathode at VCC 3.3 V rail), injecting approximately (5 V − 3.3 V − 0.7 V) / R_ESD of current into the 3.3 V supply. With a low R_ESD (a few hundred ohms), this can be several milliamperes, raising the VCC rail, resetting the MCU, or permanently damaging the input protection structure over time.
The fix options in increasing robustness: (1) a resistor voltage divider from 5 V TX to 3.3 V RX (e.g., 1 kΩ from 5V-TX to junction, 2 kΩ from junction to GND — output: 5V × 2/(1+2) = 3.33 V), limited to low baud rates because the capacitance loads the divider; (2) a single N-channel MOSFET open-drain level shifter (BSS138 or similar), which translates 5 V logic to 3.3 V by pulling the 3.3 V rail LOW through the FET; or (3) a dedicated bidirectional level translator IC such as the Texas Instruments TXS0108E (auto-direction sensing) or TXB0108 (push-pull, faster for higher baud rates).

RS-232 to MCU UART: Mandatory Level Conversion
RS-232 is defined in TIA-232 as a single-ended, unbalanced interface with inverted logic polarity: a logic-1 (MARK state) is represented by a voltage of −3 V to −15 V, and a logic-0 (SPACE state) by +3 V to +15 V. This is the opposite of CMOS/TTL logic where HIGH = logic-1. PC COM ports (DB9 connectors) output RS-232 levels. Connecting a PC RS-232 TX directly to a 3.3 V MCU RX pin applies up to +15 V to the RX pin, instantly destroying it. Connecting it to a 5 V MCU RX applies up to +15 V, with the same result.
The mandatory solution is a RS-232 transceiver IC. The MAX232 (5 V supply) and SP3232 or MAX3232 (3.3 V supply) are standard choices. These ICs use internal charge pumps to generate ±8 V to ±10 V rails from a 3.3 V or 5 V input, translate RS-232 incoming signals to CMOS levels, and translate outgoing CMOS signals to RS-232 swing. For 3.3 V MCUs, the MAX3232 or the smaller MAX3221 (1 × TX, 1 × RX) are common and require only four 100 nF charge-pump capacitors.
| ⚠️ Warning — USB-to-serial adapter voltage matters |
|---|
| FTDI FT232RL, CP2102, CH340, and similar USB-to-serial bridge ICs output CMOS logic levels, not RS-232 levels. Their TX output is typically 3.3 V or 5 V depending on the VIO supply pin. Many modules offer a solder jumper to select 3.3 V or 5 V I/O. Verify the bridge output voltage before connecting to a 3.3 V MCU: a 5 V bridge to a non-5V-tolerant 3.3 V MCU requires the same level shifting as any 5-to-3.3 V interface. The bridge also inverts the RS-232 polarity (it presents UART idle as HIGH, not the RS-232 convention), so it connects directly to MCU UART pins without any further inversion. |

Oscilloscope Measurement Technique for UART Diagnostics
An oscilloscope is the definitive diagnostic instrument for UART signal problems. A logic analyzer decodes symbols but cannot reveal the electrical quality of the signal — it cannot show overshoot, ringing, slow edge rates, or marginal logic levels. For root-cause analysis of UART failures, start with an oscilloscope.
| Measurement | What to Look For | Oscilloscope Setup | Pass / Fail Criterion |
|---|---|---|---|
| Idle line level | RX and TX should sit at logic-HIGH before any transmission | DC coupling, 1 V/div, trigger on falling edge | Idle = VCC (3.3 V or 5 V); idle LOW = inverted signal or missing pull-up |
| Start bit width | First LOW pulse after idle is the start bit; measure pulse width | Single-shot capture, 1× bit period / div | Width = 1 / baud rate ±2% (e.g. 8.68 μs at 115200) |
| Bit period uniformity | All bits should have equal width within frame | Zoom to individual bits; measure each width | All bit periods within ±3% of nominal |
| Stop bit integrity | Must be logic-HIGH for ≥1 bit period | Trigger on falling edge of stop bit (if any) | Any LOW stop bit = framing error will be flagged |
| Eye diagram (high baud rates) | Open, symmetric eye at sample point; no eye closure | Persistence mode; overlay many frames | Eye height > 50% of logic swing; eye width > 50% of bit period |
| Ringing / overshoot | Signal transitions should settle within 20–30% of bit period | High bandwidth probe; zoom to rising/falling edge | Overshoot < ±20% of supply voltage; settling within 25% of bit period |
Measuring Actual Baud Rate
To verify the actual baud rate from the transmitter without knowing the data content: trigger on the falling edge of the TX line (start bit), then capture a full frame. Identify two consecutive bits that transition from HIGH to LOW or LOW to HIGH — bit boundaries. Measure the time between adjacent same-level bits (this is one bit period). The actual baud rate = 1 / (measured bit period). Compare against the nominal bit period for the intended baud rate.
Alternatively, most oscilloscopes with serial decode capability can be set to auto-detect the baud rate from captured waveforms. Enter the protocol decoder, select UART, enable auto-baud detection, capture several bytes, and read the detected baud rate from the decode summary. This is faster than manual measurement but requires the signal to be clean enough for the auto-detect algorithm to converge.
Identifying Noise-Induced Errors
If intermittent errors are suspected but no failure is visible in a short capture, use the oscilloscope’s persistence mode (also called infinite persistence or digital phosphor mode). Set persistence to maximum (or ‘infinite’) and trigger on UART TX with a normal trigger. After several hundred or thousand frames have overlapped, any outlier transitions will appear as a smear or a secondary trace at a different level. This reveals noise spikes, ground bounce, crosstalk from adjacent signals, or glitches caused by nearby power stage switching that are present on only a small fraction of frames.
A differential probe across the GND pins of the two communicating devices will reveal ground potential differences. Any AC or DC offset greater than 0.4 V on the ground line is a source of logic-level uncertainty at the receiver and can cause intermittent framing errors under load.
Hardware Flow Control: RTS/CTS and Its Role in Error Prevention
UART hardware flow control uses two additional signals — RTS (Ready to Send) and CTS (Clear to Send) — to allow the receiver to signal the transmitter to pause when it cannot accept more data. Without flow control, a receiver that cannot empty its FIFO or buffer fast enough will experience overrun errors (ORE) and lose data, even if the electrical connection is perfect and the baud rate is correctly matched.
In the standard wired flow control configuration: the transmitter drives its RTS output LOW (asserted) to signal that it is ready to receive data. The receiver checks its CTS input before transmitting; it transmits only when CTS is asserted (LOW). When the receiver’s buffer fills, it deasserts RTS (drives HIGH), which the transmitter sees as CTS de-asserted, and the transmitter pauses until CTS is re-asserted. This handshake happens at the electrical level, below the firmware byte-handling layer, eliminating overrun errors that result from firmware latency.
| ⚠️ Common flow control wiring mistake — crossed vs straight RTS/CTS |
|---|
| RTS of device A connects to CTS of device B, and RTS of device B connects to CTS of device A. This is the cross-connection required for two DTE devices (two MCUs, two PCs). It is NOT a straight-through connection. A null-modem cable makes this crossing internally. If flow control is enabled in firmware but RTS is wired to CTS of the same device (loopback), the device is always clear to send regardless of buffer state, and the flow control has no effect. If RTS and CTS pins are left unconnected while flow control is enabled in firmware, the transmitter will never see CTS asserted and will never transmit: a symptom that looks identical to a dead UART. Disable hardware flow control in firmware if the physical RTS/CTS wires are absent. |
Signal Integrity: Cables, Termination, and EMI
Cable Length and Capacitive Loading
At low baud rates (9600 baud), UART signals can tolerate long cables (tens of metres) because the bit period (104.2 μs) is much longer than the cable RC time constant. At high baud rates (1 Mbaud, 4 Mbaud), the bit period (1 μs, 250 ns) approaches the cable’s RC time constant, causing signal edges to be rounded rather than sharp. The receiver samples near the centre of each bit, so as long as the signal reaches the correct logic level before the sample point, communication succeeds. When the cable RC delay is a significant fraction of the bit period, the signal no longer reaches the correct level before sampling, causing intermittent errors.
The rule of thumb: cable capacitance of typical ribbon or twisted-pair cable is approximately 50–100 pF/m. Driven by a CMOS output with an internal impedance of approximately 10–50 Ω, a 1 m cable has an RC time constant of approximately 1–5 μs. At 115200 baud (8.68 μs per bit), this is acceptable. At 1 Mbaud (1 μs per bit), a 1 m cable is at the limit of viability. If long cable runs are required at high baud rates, consider RS-485 (differential signalling with 100 m capability at 1 Mbaud) instead of single-ended UART.
RS-485 for Long-Distance UART Replacement
RS-485 transmits UART-framed data over a differential pair (A and B lines). It determines logic levels through the voltage difference between the two wires rather than ground. A differential voltage above +200 mV represents logic-0, while a voltage below −200 mV represents logic-1. This differential signalling reduces common-mode noise, supporting cable runs of up to 1,200 m at 100 kbaud or 100 m at 10 Mbaud.
Termination is required for long RS-485 cables to prevent signal reflections. Twisted-pair cables typically have a characteristic impedance of 100–120 Ω, so 120 Ω termination resistors are placed across the A and B lines at both ends of the bus. Without proper termination, signal reflections can cause intermittent communication errors, especially over longer cables and at higher baud rates.
| 💡 RS-485 fail-safe bias resistors for idle bus |
|---|
| When all RS-485 transmitters are idle (not driving the bus), the A and B lines float. If V(A) − V(B) is near zero volts, the receiver cannot determine whether the bus is idle or receiving a valid MARK (logic-1). Some receivers interpret a floating bus as a logic-0 (SPACE) start bit, generating continuous framing errors. Fail-safe bias resistors resolve this: a pull-up resistor (560 Ω to 1 kΩ) on the A line to VCC and a pull-down resistor to GND on the B line ensure the idle bus presents at least +200 mV differential, keeping receivers in the MARK (idle) state. These resistors are only needed at one point on the bus, typically at the master node. |
Firmware Diagnostic Techniques
Loopback Test
A loopback test is the fastest way to determine whether a UART fault is in the hardware or firmware. Connect the TX pin of the MCU directly to its own RX pin (a hardware loopback). Then transmit a known byte pattern (e.g., 0x55, 0xAA alternating) and verify that what is received exactly matches what was transmitted. If the loopback test passes, the MCU’s UART peripheral and firmware are functioning correctly and the fault is in the external cable, the remote device, or the level shifting circuitry. If the loopback test fails, the fault is in the MCU’s UART configuration, firmware, or the GPIO pin assignment (verify that the TX and RX pins are assigned to the correct alternate function in the pinmux or IO-MUX configuration).
Reading the Error Register in Firmware
After each received byte, firmware should log the UART status register value alongside the received data. During debugging, this reveals which error flags are set and at what rate. STM32 example (HAL-based): in the UART receive interrupt handler, after HAL_UART_IRQHandler() calls HAL_UART_RxCpltCallback(), the error code is available in huart->ErrorCode. The bit mask definitions (HAL_UART_ERROR_FE = 0x04, HAL_UART_ERROR_NE = 0x02, HAL_UART_ERROR_ORE = 0x08, HAL_UART_ERROR_PE = 0x01) can be tested against this value to log specific error types. Maintaining cumulative counters for each error type over time and reporting them via a debug console is the most effective way to characterise intermittent UART issues that do not appear on a single oscilloscope capture.
Auto-Baud Detection
Some UART peripherals (STM32 USART in auto-baud mode, Silicon Labs USART with autobaud, Espressif ESP32 UART in autobaud) can measure the duration of the first received character and automatically set the BRR to match the transmitter’s baud rate. Auto-baud detection is useful when the baud rate of the remote device is unknown or when targeting interoperability with multiple baud rates. It works by measuring the width of the start bit or the first 0x55 byte (which presents a known bit pattern of alternating 0 and 1). Auto-baud detection eliminates baud rate mismatch as a failure mode but does not resolve logic level incompatibility or configuration mismatches in data bits, parity, or stop bits.
Frequently Asked Questions
A UART framing error occurs when the receiver detects a LOW signal instead of the expected HIGH stop bit. Common causes include baud rate mismatch, incorrect data-bit or parity settings, electrical noise, and BREAK conditions. Checking the signal with an oscilloscope and verifying UART settings can help identify the issue.
UART typically tolerates approximately 2% combined baud rate error, although the exact limit depends on frame length and receiver oversampling. Excessive clock mismatch can shift sampling points and cause incorrect data reception. Internal RC oscillators are more likely to cause timing issues than crystal-based clocks.
A 3.3V TX may work with a 5V RX, depending on its input thresholds. However, connecting a 5V TX directly to a non-5V-tolerant 3.3V RX can damage it. Check the datasheet or use a level shifter or voltage divider to protect the 3.3V device.
A UART overrun error occurs when a new byte arrives before the previous byte has been read from the receive data register. The previous data may be lost, and the ORE flag is set. Interrupts, DMA, larger buffers, or faster data processing can help prevent overruns.
UART supports asynchronous serial communication using start and stop bits. USART supports both synchronous and asynchronous communication. RS-232 defines electrical signal levels and communication interface characteristics, so a level converter such as MAX232 is required when connecting UART logic to an RS-232 interface.
Conclusion
Reliable UART communication depends on accurate baud rate configuration, compatible logic levels, correct frame settings, and proper signal integrity. When troubleshooting issues such as garbage characters, framing errors, or data loss, start by checking the idle line state, measuring the actual baud rate, and verifying UART settings on both devices. An oscilloscope can help identify timing problems, noise, and signal-level issues, while firmware error flags reveal reception and buffer-related faults.
For reliable operation, use suitable clock sources, proper level shifting, adequate receive buffers, and hardware flow control when needed. These checks help identify UART communication problems early and improve system stability across embedded applications.

COMMENTS