UART (Universal Asynchronous Receiver/Transmitter) :

 

 What is UART?

UART (Universal Asynchronous Receiver/Transmitter) is a hardware communication protocol used for serial communication between two devices. It is simple, widely used, and requires only two wires:

  • TX (Transmit)

  • RX (Receive)


UART Communication Characteristics :
  • Asynchronous: No shared clock between devices.
  • Baud Rate: Both devices must agree on the speed (e.g., 9600, 115200 bits/sec).
  • Framing: Each byte is wrapped with a start bit and stop bit.
  • Optional Parity: For error checking.

UART Data Frame Format :

Start Bit    Data Bits (5-8)    Parity Bit (Optional)   Stop Bit(s)
0 e.g. 01100001            e.g. 0      1


void UART_init(unsigned int baud) {
    unsigned int ubrr = F_CPU / 16 / baud - 1;
    UBRR0H = (ubrr >> 8);
    UBRR0L = ubrr;
    UCSR0B = (1 << RXEN0) | (1 << TXEN0); // Enable RX and TX
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // 8-bit data
}

void UART_send(char data) {
    while (!(UCSR0A & (1 << UDRE0))); // Wait for empty buffer
    UDR0 = data;
}

char UART_receive(void) {
    while (!(UCSR0A & (1 << RXC0))); // Wait for data
    return UDR0;
}




 Real Use Cases

  • Arduino to PC (USB acts as UART)

  • Vehicle ECUs to diagnostic tools

  • Sensor modules (GPS, Bluetooth, etc.)



Comments

Popular posts from this blog

Implementation of Queue using Array

Printing the odd and even no using Pthread

Print even and odd using two thread in synchronized way