0% found this document useful (0 votes)
10 views

Understanding UART Protocol_ A Comprehensive Guide

Uart

Uploaded by

Pate Vishnu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Understanding UART Protocol_ A Comprehensive Guide

Uart

Uploaded by

Pate Vishnu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

UART PROTOCOL

What is UART?
➢ UART (Universal Asynchronous Receiver/Transmitter) is a hardware
communication protocol used for asynchronous serial communication. It is
a crucial component in the world of electronics and embedded systems,
enabling communication between devices such as microcontrollers,
computers, and peripherals.
➢ The UART (Universal Asynchronous Receiver/Transmitter) protocol is a
common communication protocol used in embedded systems for serial
communication between devices. It's asynchronous because there's no
separate clock signal shared between the sender and receiver; instead, both
devices agree on a specific baud rate.

Key Features of UART


1. Asynchronous Communication: No clock signal is needed; devices must
agree on baud rate (data transfer speed).
2. Full-Duplex Communication: Separate transmit (TX) and receive (RX)
lines allow simultaneous two-way communication.
3. Data Framing: Data is transmitted in frames, each consisting of a start bit,
data bits (typically 8), an optional parity bit, and one or more stop bits.
4. Error Checking: Optional parity bit allows simple error detection.

The UART communication typically involves two pins:


TX (Transmit): The pin where the microcontroller sends data.

RX (Receive): The pin where the microcontroller receives data.


• The main purpose of a transmitter and receiver line for each device is to
transmit and receive serial data intended for serial communication.

The transmitting UART is connected to a controlling data bus that sends data in
a parallel form. From this, the data will now be transmitted on the transmission
line (wire) serially, bit by bit, to the receiving UART. This, in turn, will convert
the serial data into parallel for the receiving device.

The UART lines serve as the communication medium to transmit and receive one
data to another. Take note that a UART device has a transmit and receive pin
dedicated for either transmitting or receiving.

For UART and most serial communications, the baud rate needs to be set the
same on both the transmitting and receiving device. The baud rate is the rate at
which information is transferred to a communication channel. In the serial port
context, the set baud rate will serve as the maximum number of bits per second
to be transferred.

How UART Works:


UART works by converting parallel data from a microcontroller into serial form
for transmission, and vice versa for reception. Here’s a breakdown of the process:

1. Data Transmission:
o Idle State: The transmission line is held high (logic 1) when idle.
o Start Bit: Data transmission begins with a start bit (logic 0),
indicating the start of a data packet.
o Data Bits: Following the start bit, data bits are sent, usually in
configurations of 5, 6, 7, 8, or 9 bits.
o Parity Bit (Optional): An optional parity bit can be added for error
checking.
o Stop Bit(s): The data packet ends with one or two stop bits (logic 1),
2. Data Reception:
• The receiver monitors the transmission line and detects the start bit.
• It then samples the incoming data bits, reconstructs the original data,
checks for parity (if used), and finally detects the stop bit to complete
the reception process.

UART Communication protocol Format:


A typical UART frame consists of:

• 1 Start Bit
• 5-9 Data Bits
• 1 Parity Bit (optional)
• 1 or 2 Stop Bits
Baud Rate:
The baud rate defines the speed of data transmission in bits per second (bps). Both
communicating devices must agree on a common baud rate to ensure proper data
exchange. Common baud rates include 9600, 115200, etc.

STM32 UART Features:


• Full duplex, asynchronous communications.
• Configurable oversampling method by 16 or by 8 to give flexibility
between speed and clock tolerance. Fractional baud rate generator systems
– Common programmable transmit and receive baud rate (refer to the
datasheets for the value of the baud rate at the maximum APB frequency.
• Programmable data word length (8 or 9 bits).
• Configurable stop bits - support for 1 or 2 stop bits.
• Separate enable bits for transmitter and receiver.

Why UART in STM32?


STM32 microcontrollers, known for their versatility and performance, often rely
on UART for various communication needs. Whether you’re developing IoT
applications, interfacing with sensors, or setting up serial communication for
debugging, UART provides a reliable and straightforward solution

STM32 and UART


The STM32F401RBT6 microcontroller, part of the STM32F4 series by
STMicroelectronics, features multiple UART interfaces. Here’s how UART
communication is typically set up and used in this MCU:

1. Clock Configuration:

• The peripheral clock for the UART module must be enabled in the RCC
(Reset and Clock Control) settings.

2. Pin Configuration:

• GPIO pins are configured for UART functionality. For instance, USART2
might use PA2 for TX and PA3 for RX.
3. Baud Rate Setting:

• The baud rate register is set to match the desired communication speed,
e.g., 9600 bps.

4. UART Initialization:

• Parameters such as word length (e.g., 8 bits), stop bits (e.g., 1 stop bit),
parity (e.g., none), and mode (transmit/receive) are initialized.

5. Data Transmission and Reception:

• Data transmission and reception are managed via the UART interface, with
the MCU handling the data framing, parity check, and signalling.

UART INTERRUPTS:

• Single interrupt per module, cleared automatically.


• Interrupt conditions:
– Overrun error
– Break error
– Parity error
– Framing error
– Receive timeout-when FIFO is not empty and no further data is
received over a 32-bit period.
– Transmit – generated when no data present (if FIFO enabled, see
next slide).
– Receive – generated when character is received (if FIFO enabled,
see next slide).
• Interrupts on these conditions can be enabled individually.
• Your handler code must check to determine the source of the UART
interrupt and clear the flag(s).

Practical Applications
1. Debugging: UART is frequently used to send debug information to a
terminal, allowing developers to monitor the state of the system.
2. Peripheral Communication: UART is ideal for communicating with
peripherals like GPS modules, sensors, and Bluetooth devices.
3. Firmware Updates: UART bootloaders enable firmware updates,
simplifying the update process.

Exploring UART functional block:


Now let’s explore the USART functional diagram in the STM32f4xx
microcontroller.
Advantages of UART:
• Simplicity: Easy to implement and use.
• Low Cost: Requires minimal hardware resources.
• Error Checking: Optional parity bit provides basic error checking

Limitations of UART:
• Limited Distance: Effective over short distances.
• Limited Speed: Not suitable for high-speed communication compared to
other protocols like SPI or I2C.
• Point-to-Point: Limited to communication between two devices.

You might also like