Skip to main content

Introduction to USART

1. USART Definition

USART (Universal Synchronous/Asynchronous Receiver/Transmitter) is a communication protocol used to transfer data between electronic devices, such as microcontrollers, sensors, and other components. This protocol is highly flexible as it supports two main modes:

  • Synchronous
  • Asynchronous

2. Operating Modes

A. Asynchronous Mode

In this mode, the USART module transmits data without an external clock signal. Synchronization is achieved using data frames consisting of:

  • Start Bit: Indicates the beginning of transmission.
  • Data Bits: Contains the primary information (typically 5-9 bits).
  • Parity Bit (Optional): Used for error detection (Even, Odd, or None).
  • Stop Bit: Indicates the end of transmission.

Characteristics: Suitable for long-distance communication or between devices that do not share the same clock.

B. Synchronous Mode

Uses a clock signal to synchronize data transfer between the transmitter and the receiver.

  • Requires the same clock configuration on both devices.
  • Allows for faster and more reliable data transfer compared to asynchronous mode.

Characteristics: Ideal for multimedia applications or high-speed bulk data transfers.

3. Configuration and Baud Rate

To use USART, several parameters must be defined:

  1. Baud Rate: The speed of data transmission (bits per second).
  2. Data Format: The number of data bits, parity, and stop bits.
  3. Interrupt: Enables notifications when data is finished being sent or received.

Baud Rate Calculation Formula (UBRR)

The UBRR (USART Baud Rate Register) value is calculated based on the CPU clock frequency ($F_{CPU}$)F_CPU) and the desired Baud Rate:

$$UBRR = \frac{F_{CPU}}{(F_CPU / (16 \times* \text{BAUD}}BAUD)) - 1$$1

Calculation Example:
If $F_{CPU}F_CPU = 16 \text{ MHz}$MHz and the target $\text{BAUD}BAUD = 9600 \text{bps:

bps}$:
    $$
  1. UBRR = \frac{(16,000,000}{000 / (16 \times* 9600}9600)) - 1$$1
  2. $$
  3. UBRR = 104.16 - 1
  4. \approx
  5. UBRR 103$$

    103
     (Hex: 0x67)