Skip to content

UART Documentation

Introduction

Universal Asynchronous Receiver/Transmitter (UART) is a simple, widely-used serial communication protocol for sending and receiving data between two devices. It is asynchronous, meaning it does not use a clock line; instead, both devices agree on a baud rate.

UART is commonly used for debugging, logging, and connecting microcontrollers to sensors or computers.

How It Works

  • Two wires: TX (transmit) and RX (receive).
  • Baud rate: Both devices must operate at the same speed (e.g., 9600, 115200 bps).
  • Start/stop bits: Each byte is framed with a start bit, optional parity bit, data bits (usually 8), and stop bit(s).
  • Flow control: Optional RTS/CTS lines can prevent data loss.

Diagram – Basic UART Connection

Device A TX ---> RX Device B
Device B TX ---> RX Device A

Use Cases

  • Debugging via serial console
  • Microcontroller-to-PC communication
  • Sending sensor readings to another board
  • Controlling actuators via serial commands

Common Pitfalls / Gotchas

  • Cross TX/RX: Transmit of one device must go to receive of the other.
  • Baud rate mismatch: Can cause garbled data.
  • Voltage level mismatch: Ensure both devices use compatible logic levels (3.3V vs 5V).
  • Noise: Long wires may introduce errors; keep short or use shielding.

Tools to Debug

  • Serial monitor (Arduino IDE, PlatformIO, PuTTY)
  • USB-to-UART adapters (FTDI, CP2102)
  • Logic analyzer for timing issues

References

Onboarding Tutorial (ESP32 or STM32)

Goal: Send a message from one board to another over UART and print it on serial monitor.

Materials

  • 2× ESP32 or STM32 boards
  • Jumper wires

Steps

  1. Connect TX of board A → RX of board B and TX of B → RX of A.
  2. Flash transmitter code on board A and receiver code on board B.
  3. Open serial monitor on board B to see incoming messages.
// Example Arduino-style pseudo-code for Transmitter
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("Hello from Board A!");
  delay(1000);
}

// Receiver
void setup() {
  Serial.begin(115200);
}

void loop() {
  if (Serial.available()) {
    String msg = Serial.readStringUntil('\n');
    Serial.println("Received: " + msg);
  }
}

Mini Challenges

  • Modify the transmitter to send a counter value instead of a static message.
  • Add a second receiver and verify both boards receive the same message.
  • Implement simple flow control using RTS/CTS lines.