Chapters

29 UART and RS-232 Protocols

networking-core
wired
comm
uart

A sensor console prints nonsense when connected to a legacy instrument. The connector fits, but that says little about its voltage levels or serial frame settings. Prove the electrical connection before trying random baud rates.

29.1 Start With Two Devices Sending Bytes

Prove Both Boards Read the Same Byte

Picture a sensor board printing clear text until it is connected to a second board and the display becomes nonsense. A microcontroller means a small computer on one chip that reads inputs and controls a device.

Name the two boards, voltage levels, ground, speed, frame settings, and expected byte. Test a correct link, wrong speed, missing ground, and reversed transmit and receive wires.

Keep the wiring, settings, sent bytes, received bytes, and logic trace. This proves one serial link, not the meaning of every message; the deeper sections cover UART timing, RS-232 levels, framing, buffering, and fault diagnosis.

UART is the simplest useful story for many devices: one side sends timed bits, the other samples them, and both must agree on framing and speed. There is no shared clock wire to rescue a mismatch.

That simplicity is why UART is common for consoles, sensors, modules, and debugging. It also means the evidence must be practical: voltage level, ground reference, baud rate, framing, and what each received byte is supposed to mean.

29.2 Overview: UART Sends Bytes Without A Clock Wire

UART is the simple asynchronous serial link used for debug consoles, GPS receivers, radio modules, bootloaders, and many board-to-board IoT connections. One wire transmits, one wire receives, and a shared ground gives both devices the same voltage reference.

The simplicity has a condition: both ends must already agree on baud rate, frame format, logic voltage, and flow-control behavior. UART does not carry an address, a clock, or a built-in retry scheme, so wiring and configuration mistakes show up as silence or garbled characters.

The design boundary is the important lesson. A microcontroller UART peripheral defines byte timing and framing; it does not define connector shape, cable robustness, message boundaries, or safe voltage levels. TTL UART on a board may idle at 3.3 V or 5 V logic. RS-232 inverts the logic and uses higher positive and negative voltages through a transceiver. RS-485 can carry UART-style bytes over a differential multidrop electrical layer, but then direction control, termination, and bus ownership become part of the release record.

For IoT products, UART is strongest as a local service, configuration, or module link: a boot console, GPS NMEA stream, AT-command modem, serial sensor, or factory programming port. It becomes fragile when teams treat it as a complete protocol. If bytes can be lost, delayed, or inserted during reset, the application needs explicit message framing, checksums, timeouts, retry rules, and buffer-overflow behavior above the serial link.

Figure 29.1 makes overview: uart sends bytes without a clock wire inspectable through UART structure showing transmit and receive. Those diagram labels establish the scope of uart is point-to-point: tx on one device must reach rx on the other, and both sides need a common ground.

A UART frame runs from idle high through a low start bit, 5–9 data bits, optional parity and 1–2 stop bits.
Figure 29.1: UART is point-to-point: TX on one device must reach RX on the other, and both sides need a common ground.

Compare UART structure showing transmit with receive inside the visual at Figure 29.1. Next find ground, which completes the scope of uart is point-to-point: tx on one device must reach rx on the other, and both sides need a common ground. The decision in overview: uart sends bytes without a clock wire must preserve that labelled boundary.

To test overview: uart sends bytes without a clock wire, open the diagram in Figure 29.2. UART Frame Structure supplies one named condition; Asynchronous serial communication frame format supplies the necessary comparison for a receiver synchronizes on the start bit, samples the data bits by timing, optionally checks parity, then waits for the stop bit.

UART frame showing idle state, start bit, data bits, optional parity, and stop bit.
Figure 29.2: A receiver synchronizes on the start bit, samples the data bits by timing, optionally checks parity, then waits for the stop bit.

Locate UART Frame Structure on Figure 29.2 before checking Asynchronous serial communication frame format. The visual’s third anchor, TIMING DIAGRAM, completes a receiver synchronizes on the start bit, samples the data bits by timing, optionally checks parity, then waits for the stop bit. Carry UART Frame Structure into overview: uart sends bytes without a clock wire; use TIMING DIAGRAM as its limiting condition.

Frame Format

8N1 means 8 data bits, no parity, and 1 stop bit. With the start bit included, one data byte uses 10 bit times on the wire.

Baud Rate

Both devices must sample at the same bit timing. Common IoT settings include 9600 for sensors and 115200 for debug consoles.

Electrical Layer

TTL UART, RS-232, and RS-485 can carry similar serial bytes, but their voltages and wiring are not interchangeable.

Boundary to remember: UART describes the byte framing. RS-232 describes an older electrical interface with inverted, higher-voltage signaling. A microcontroller UART pin is not an RS-232 port unless a level shifter is present, and a working USB serial adapter test does not prove the final harness, grounding, or enclosure routing.

29.4 Under The Hood: Timing Error Accumulates Across The Frame

UART receivers usually resynchronize on the start edge, then sample near the center of each bit period. Because there is no shared clock, any transmitter and receiver timing error accumulates until the frame ends. Longer frames, poor oscillators, noisy edges, and high baud rates all reduce the margin.

A receiver commonly oversamples the line, detects the falling start edge, waits toward the center of the first data bit, and then samples each following bit at the configured interval. If the local clock is too fast or too slow, those sample points drift. In an 8N1 frame the receiver only needs to stay aligned for one start bit, eight data bits, and one stop bit, then it can resynchronize on the next start bit. That is why moderate clock error can work for short frames but fail with long words, parity, two stop bits, or marginal edges.

To test under the hood: timing error accumulates across the frame, open the diagram in Figure 29.6. USB vs RS-232 supplies one named condition; USB supplies the necessary comparison for asynchronous serial links depend on both endpoints keeping close enough timing until the stop bit is sampled.

Locate USB vs RS-232 on Figure 29.6 before checking USB. The visual’s third anchor, RS-232, completes asynchronous serial links depend on both endpoints keeping close enough timing until the stop bit is sampled. Carry USB vs RS-232 into under the hood: timing error accumulates across the frame; use RS-232 as its limiting condition.

In 8N1, every byte consumes 1 start bit, 8 data bits, and 1 stop bit. At 9600 baud, that gives about 960 data bytes per second before protocol overhead. At 115200 baud, the byte rate is about 11,520 bytes per second, but electrical and timing margin become more sensitive to cable and oscillator quality.

Throughput is not only baud divided by frame length. A real product may pause between messages, wake a modem, wait for line turnaround, process AT responses, or copy bytes through interrupt handlers into a ring buffer. If the consumer task stalls, bytes can overrun even when the electrical link is perfect. That is why serial diagnostics should log framing errors, parity errors, overrun counts, buffer high-water marks, and message checksum failures separately.

Before under the hood: timing error accumulates across the frame, inspect Figure 29.7: Alternative view must be considered with IoT Platform. That visual pairing grounds uart trades addressing and shared-clock features for a simple point-to-point byte stream in named evidence.

An alternative IoT platform view has partial text about each serial protocol excelling in different uses and a Module A label.
Figure 29.7: UART trades addressing and shared-clock features for a simple point-to-point byte stream.

At Alternative view in Figure 29.7, compare the diagram with IoT Platform; then locate Each serial. That labelled check bounds uart trades addressing and shared-clock features for a simple point-to-point byte stream. For under the hood: timing error accumulates across the frame, retain Each serial as evidence for the resulting choice.

Clock Error

Keep combined transmitter and receiver error to only a few percent across the whole frame; crystal-based clocks usually make this easier than uncalibrated RC clocks, especially across temperature.

Signal Integrity

Cable capacitance, weak drivers, poor grounds, connector oxidation, and EMI slow edges or shift thresholds, especially at higher baud rates.

Error Handling

Parity can detect some single-bit errors, but robust IoT protocols still need message framing, checksums, sequence or length fields, timeouts, and retry behavior above UART.

29.5 Separate a Framing Error from a Voltage Mismatch

Use an illustrative UART frame with one start bit, eight data bits, no parity and one stop bit. It occupies ten bit periods per byte. At 19,200 bits per second, one bit lasts about 52.08 microseconds and a full frame takes about 520.8 microseconds. A 64-byte record takes about 33.33 ms without gaps. Application framing, such as a length field or newline, sits above this byte timing.

Now compare a receiver configured for 9,600 bits per second. Its nominal bit period is about 104.17 microseconds, twice the transmitter’s. It samples the incoming signal on the wrong time scale, so clean voltage transitions cannot produce the intended byte stream. Correct both ends to the same speed and frame settings before interpreting the payload.

Read Figure 29.2 from the start transition through data and stop. The receiver uses that transition to establish timing for one frame. The wiring figure at Figure 29.1 then connects transmit to receive with the required reference. Timing and wiring are separate checks.

Predict whether a DB9 connector proves compatibility with a microcontroller input. It does not identify safe pin voltages. RS-232 signalling needs the appropriate electrical interface; direct connection to a low-voltage UART pin can be unsafe for the component. Next, suppose the bytes decode correctly but records occasionally disappear. Check buffering and processing time, because a valid frame does not prevent software overflow.

For example, an incoming 64-byte burst fills a 64-byte receive buffer completely if nothing is removed during that interval. The next byte needs space or an explicit overflow policy. Adding a shared clock is not the remedy; servicing the buffer or controlling the source rate addresses the observed failure.

This module makes serial troubleshooting a sequence of measurable boundaries. Establish levels, reference and pinout; verify speed and frame; then check byte handling and message meaning. A successful text line is a useful starting observation, but the sustained record stream is the service that must survive.

29.6 Summary

UART is a simple asynchronous byte stream for IoT debug consoles, sensors, modules, and legacy equipment. It works when both sides agree on baud rate and frame format, TX/RX are crossed with a shared ground, the electrical layer is compatible, and sustained traffic has an overflow strategy. RS-232 is not the same as a microcontroller UART pin; translate the voltage before connecting it.

29.7 Key Takeaway

Treat every serial link as a record of framing, timing, wiring, voltage, and evidence. Most UART failures are not mysterious protocol bugs; they are mismatched settings, unsafe voltage levels, missing ground, weak timing margin, or unchecked buffering.

29.8 See Also

Wired Communication Fundamentals

Review synchronous versus asynchronous links and the design reasons wired buses persist in IoT.

I2C Serial Bus

Compare UART point-to-point wiring with a shared two-wire addressed bus.

SPI Serial Bus

Compare asynchronous UART with a clocked, chip-select-based serial interface.

Wired Ethernet Physical Layer

See when a serial byte stream should give way to packetized network infrastructure.