Past exam question: Assignment 3, Q15
Open in the Padhaiko appExplain UART in detail with example.
Solution
What is UART and Hardware Connection: UART (Universal Asynchronous Receiver-Transmitter) is a hardware communication peripheral that transmits and receives serial data asynchronously without a shared clock line. Two UART devices cross-connect their transmit and receive pins (TX RX and RX TX) with a common GND. Because there is no clock wire, both sides must be pre-configured to the exact same baud rate (commonly or ) and frame format (e.g., 8N1: 8 data bits, No parity, 1 stop bit).
+------------+ TX ----------> RX +------------+
| Transmitting| | Receiving |
| UART | RX <---------- TX | UART |
+------------+ +------------+
GND ---- GND
Frame Format (Idle HIGH -> Start LOW -> D0..D7 LSB first -> [Parity] -> Stop HIGH):
Idle | Start | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | Parity | Stop | Idle
HIGH | 0 | b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7 | (opt) | 1 | HIGHFive Steps of UART Data Transmission:
- Parallel Load: The transmitting UART receives a parallel byte (e.g., 8 bits) from the CPU/microcontroller data bus.
- Framing: It adds a Start bit (
0), optional Parity bit (for single-bit error detection), and Stop bits (1) around the data bits. - Serial Shift-Out: It shifts the frame out bit-by-bit (LSB first) on the
TXline at the configured baud rate; the receiving UART detects the falling edge of the Start bit and samples each bit at mid-bit intervals. - Deframing: The receiving UART verifies parity/stop bits and strips the Start, Parity, and Stop bits.
- Parallel Read: It converts the serial bits back into a parallel byte and places it on its receive buffer/data bus (flagging
RXready).
Practical Example (Arduino Sensor Telemetry over UART): Sending the ASCII character 'A' (0x41 = 0100 0001) in 8N1 format at transmits the 10-bit sequence: 0 (Start) + 1 0 0 0 0 0 1 0 (LSB-first 0x41) + 1 (Stop).
void setup() {
Serial.begin(9600); // Configure hardware UART at 9600 bps, 8N1
}
void loop() {
int adcVal = analogRead(A0);
Serial.print("Sensor ADC = ");
Serial.println(adcVal); // Sends framed ASCII bytes over TX (PD1)
delay(500);
}- Pros: Only 2 signal wires, full-duplex, built-in parity error check, no clock line needed.
- Cons: Point-to-point only (-to-), slower than SPI, baud rates must match within .
UART is an asynchronous, full-duplex, 2-wire (TX/RX) serial protocol where both devices agree on a common baud rate and frame structure (Start bit + Data bits + optional Parity + Stop bits). The transmitter converts parallel bytes into framed serial bits and shifts them out LSB-first; the receiver synchronizes on the Start bit, samples the data bits, strips framing bits, and reconstructs the parallel byte (e.g., Serial.begin(9600) streaming ADC readings to a PC).