What is UART? The simplest serial interface in embedded systems
Atlasbot · 16/8/2026 · 11 min read
When you need two devices to "talk" to each other — an MCU with a computer, an MCU with a GPS module, or two control boards in the same robot — UART is often the first choice because it's the simplest: just 2 wires, no complicated configuration needed, and nearly every microcontroller has at least one UART port available.
Key concepts
UART (Universal Asynchronous Receiver/Transmitter) transmits data serial (bit by bit, on one wire) instead of in parallel (multiple bits at once, multiple wires) — trading speed for simplicity: just TX (Transmit) and RX (Receive) wires, no Need any other signal wire? The word "Asynchronous" means no separate clock wire — the two sides must agree in advance on the transmission rate (baud rate, for example 9600 or 115200 bits/second) to automatically count the time at the right time to sample each bit.
Each byte of data is packaged in a frame consisting of: 1 start bit, 8 data bits, optionally 1 parity bit, and 1 stop bit.
UART connections must always be "cross-wired".
The TX pin of device A must be connected to the RX pin of device B, and vice versa — connecting TX to TX (a very common mistake among newbies) causes both sides to "talk" without anyone "listening".
In short: UART is simple, cheap, widely available — but only communicates 1-to-1 between two devices; If multiple devices need to share the same bus, they must use I2C or SPI.
How it works
Transmission line idle = high level (1)
___ ___ ___ ___ ___ ___ ___ ___ ___ _______
| | | | |
|___|___|_D0_D1_D2_D3_D4_D5_D6_D7_______|___|
Start 8 data bits (LSB first) Stop
Configuring UART with Arduino only requires one line, specifying the correct baud rate as agreed by both parties:
void setup() {
Serial.begin(115200); // Must match the baud rate with the other device
}
void loop() {
if (Serial.available()) {
char c = Serial.read(); // Read 1 byte just received via RX
Serial.write(c); // Resend via TX
}
}
Because there is no common clock wire, if the two sides differ by even a few percent in baud rate, the bit sampling will gradually drift over time — this is why getting junk characters when baud rate is misconfigured is the most common UART error.
Technical details
Formulas
The transmission time for 1 bit and 1 frame is calculated directly from the baud rate — useful to estimate whether the UART is fast enough for the amount of data to be sent:
1 bit time = 1 / baud rate
Time 1 frame (start + 8 data + stop, no parity) = 10 bits × time 1 bit
VD: baud rate = 9600
1 bit time = 1/9600 ≈ 104µs
Time to send 1 byte = 10 × 104µs ≈ 1.04ms
→ Sending an NMEA sentence from GPS ~70 bytes long takes ≈ 73ms at this baud rate
Parameters
Common baud rates and practical limits of hardware UART on microcontroller:
| Baud rate | Typical application |
|---|---|
| 9600 | Old default, cheap GPS/Bluetooth module |
| 115200 | Most popular today for debug/logging via Serial Monitor |
| 230400 – 921600 | High-speed large data transmission (e.g. 2D LiDAR over UART) |
The hardware UART on the AVR (Arduino Uno) operates stably up to about 115200-250000 bps in practice although theoretically higher; UART on STM32/ESP32 supports up to several Mbps depending on peripheral clock configuration.
Register / Bit / Byte
The actual baud rate on the STM32 is calculated from a single configuration register — USART_BRR (Baud Rate Register) — based on the clock frequency supplied to the UART peripheral and the oversampling factor (usually x16):
USARTDIV = f_CK / (16 × desired baud rate)
VD: f_CK = 42MHz, baud rate = 115200
USARTDIV = 42.000.000 / (16 × 115200) ≈ 22.8
The HAL library calculates this value itself and loads it into USART_BRR when calling the UART initialization function — understanding the formula helps explain why some clock/baud rate combinations give larger rounding errors than others, even though both "work".
Protocol
UART itself is just that physical layer + bit frame (physical + framing layer) — does not define the structure of the data sent. Higher layer protocols are based on UART, for example NMEA 0183 — the most common GPS data format standard, each sentence begins with $, fields separated by commas, ending with checksum (eg: $GPGGA,123519,4807.038,N,...*47) — the GPS module sends these sentences continuously via UART at a fixed baud rate (usually 9600).
Practical applications
In an AMR, UART often connects STM32 (real-time control layer) with GPS/GPS RTK module to receive absolute position, or as a simple communication channel between two boards (eg motor control board sends odometry data to board running ROS2) when extremely high speed is not needed or many devices share the same bus - exactly the strength of "simple, 1-to-1" mentioned in the Main Concepts section.
Practical example
// Arduino sends commands, waits, and reads responses via UART
void setup() {
Serial.begin(115200);
Serial.println("PING");
}
void loop() {
if (Serial.available()) {
String response = Serial.readStringUntil('\n');
Serial.print("Nhan duoc: ");
Serial.println(response);
}
}
Output on Serial Monitor (baud rate 115200, matching both sides):
PING
Nhan duoc: PONG
Output if the baud rate is different (eg: send at 115200, read at 9600):
ؤ±ýÿ£þ... ← garbage character due to incorrect bit timing sampling
The garbage character in the last line illustrates exactly the consequences of the baud rate deviation mentioned in the Principle of Operation section - it is not a hardware error, it is simply that the two sides "count time" at a different rate, so they sample the wrong bit position.
Common mistakes
- Baud rate difference between the two sides — the most common cause of junk characters, illustrated above — always check that both sides are configured to the same value.
- Forgot to connect the common GND between the 2 boards — UART only has TX/RX, does not carry a voltage reference itself — missing a common GND wire causes the HIGH/LOW voltage level of the 2 boards not to be the same reference standard, easily reading wrong bits or not receiving anything.
- Pairing a 5V UART directly with a 3.3V UART without going through a level conversion circuit — For example: Arduino Uno (5V) connected directly to the ESP32 (can only handle 3.3V) can damage the RX pin of the ESP32 — needs a voltage divider circuit or logic level conversion IC in the middle.
- Not reading data fast enough, causing buffer overflow (overrun) — if the main program is busy doing something else for too long while the UART continuously receives new bytes, the receive buffer is full and the old data is lost — the flag
ORE(Overrun Error, mentioned in the Bit manipulation article) on the UART status register accurately indicates this error.
Conclusion
UART is the most logical starting point for learning hardware interfacing — simple, widely available, and sufficient for most 1-to-1 needs between two devices. Mastering how to calculate frame times, the meaning of status flags, and the causes of garbage characters is the foundation before moving on to more complex standards. The next article in this section is about I2C - a communication standard that allows multiple devices to share a common bus, something UART cannot do.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.