Computer applicationsElectronic projectsMicrocontrollers Projects

UART PROTOCOL: DESCRIPTION OF WORK

UART PROTOCOL: DESCRIPTION OF WORK

UART (Universal Asynchronous Transmitter Receiver) is the most common protocol used for full duplex serial communications. The device sends and receives data from one system to another. In this manual, we will study in detail the basics of communication and the operation of the UART protocol, a detailed description of the interface and pinout of the connectors..

WHAT IS UART

UART stands for Universal Asynchronous Receiver Transmitter. This is the peripheral equipment that is inside the microcontroller. The function of the UART is to convert the incoming and outgoing data into a serial bit stream. Eight-bit serial data received from a peripheral is converted to parallel form using serial-to-parallel conversion, and parallel data received from the CPU is converted using serial-to-parallel conversion. This data is presented in modulating form and is transmitted at a specific bit rate.

WHY USE UART

Protocols such as SPI (Serial Peripheral Interface) and USB (Universal Serial Bus) are used for fast communication. But when high-speed data transfer is not required, the UART protocol is used. It is a low cost communication device with one transmitter and receiver. It requires only one wire for data transmission and one for reception. Read about the USB-ART converter here.

It can be connected to a personal computer using an RS232-TTL or USB-TTL converter. The similarity between RS232 and UART is that they both don’t need a timer to send and receive data. A UART frame consists of 1 start bit, 1 or 2 stop bits, and a parity bit for serial communication.

UART BLOCK DIAGRAM

The UART consists of the following main components: a transmitter and a receiver. The transmitter consists of a transmit hold register, a transmit shift register, and control logic. Similarly, a receiver consists of a receive hold register, a receiver shift register, and control logic. Typically, both transmitter and receiver are equipped with a data rate generator.

The baud rate generator determines the rate at which the transmitter and receiver must send and receive data. The transmit hold register contains the data byte being transferred. The transmit shift register and the receive shift register shift bits left or right until a data byte is sent or received.

In addition, read or write control logic is provided to indicate when to read and write. The baud rate generator generates baud rates ranging from 110 bps to 230400. In most cases, microcontrollers offer higher baud rates, such as 115200 and 57600 bps, but devices such as GPS and GSM use lower baud rates of 4800 and 9600 baud

HOW UART WORKS

The transmitter and receiver use the start bit, stop bit, and timing parameters to communicate with each other. The source data is in parallel form. For example, there is 4-bit data, and in order to convert it into serial form, you need a converter from parallel to serial. Typically, D-flip-flops are used to design converters.

A D flip-flop, also known as a data flip-flop, shifts one bit from the input side to the output side only when the timer changes the transition from high to low or from low to high. Similarly, if 4 bits of data need to be transmitted, 4 flip-flops are needed.

  • D – input data.
  • CLK – clock signal.
  • Q is the output.

Now let’s design a converter from parallel to serial and from serial to parallel.

PARALLEL TO SERIAL CONVERSION

Step 1: Take 4 triggers. The number of flip-flops is equivalent to the number of transmitted bits. In the same way, we put multiplexers before each trigger, but excluding the first one. A multiplexer is installed to combine data and convert it into serial bits. It has two inputs, one is a parallel data bit and the other is from a previous flip-flop.

Step 2: Now we load data at a time into D-flip-flops. It will fetch the parallel data and move the last bit of the last trigger – the fourth, then the third bit, the second and finally the first bit. Now another converter is used to convert parallel data to serial form.

SERIAL TO PARALLEL CONVERSION

Step 1: Take 4 triggers. The number of flip-flops is the same as the number of transmitted bits.

Step 2: First, turn off the parallel bus. We do not turn it on until all the bits are loaded. Let’s store the data at the input of the first trigger. Now we set the clock high level, this will shift the least significant bit to the input of the second trigger and the output of the first. In the same way, we will shift all the bits one by one, making the clock pulse high. The converter is in the hold state until all bits have been sent to the output.

Step 3: Each flip-flop now contains one bit of serial data. While all bits are being sent to the trigger output, activate the bus. This will force the converter to send all the bits at once.

UART PROTOCOL FORMAT

Communication starts with start bit “0”. The start bit initiates the transfer of serial data, and the stop bit ends the data transaction.

It also has a parity bit (even or odd). A parity bit is represented as “0” (an even number of 1s), and an odd parity bit is represented as a “1” (an odd number).

DATA TRANSFER

Data transmission is carried out on a single transmission line (TxD). Here, “0” is treated as a space, and “1” as the mark state.

The transmitter sends one bit at a time. After sending one bit, the next one is sent. Thus, all data bits are sent to the receiver at a predetermined baud rate. There will be a certain delay in the transmission of each bit. For example, to send one byte of data at 9600 baud, each bit is sent with a delay of 108 µs. The data is appended with a parity bit. Thus, 10 bits of data are required to send 7 bits.

When transmitting, the LSB (Least Significant Bit) is always transmitted first.

DATA RECEPTION

The receiving line RxD is used to receive data.

UART INTERFACE EXAMPLE

This example demonstrates how the ESP8266 UART interacts with the MAX232. The MAX232 is powered by a 5V supply and includes a capacitive voltage generator to drive the 232 level voltage. It comes with two transmitters, also called a driver (Tin, Tout) and receivers (Rin and Rout).

Here I used an ESP8266 (32-bit microcontroller) with a built-in UART. Communication can be done with ESP8266 using AT commands via RS232 to TTL level converter (MAX232). The diagram shows the connection of the ESP8266 to the computer.

When requesting valid AT commands through the PC, the Wi-Fi chip will respond with an acknowledgment. Here are the steps to implement serial communication with PC.

  1. Connect the transmitter (TX) of the ESP8266 to the receiver (RX) of the RS232 to TTL level converter (MAX232) and the PC receiver.
  2. Connect the receiver (RX) of the ESP8266 to the TX of the PC and the RX of the TTL converter.

ESP8266 COMMANDS

The following shows the response of the ESP8266 module.

UART AND USART

USART is the basic form of UART. Technically they are not the same thing, but the definition for them is the same. These are microcontroller peripherals that convert parallel data to serial bits and vice versa.

UART USART
The timings are generated inside the microcontroller. The sending device will generate the timing.
Data transfer rate is low. Data transfer rate is higher due to external timings.
Standalone Protocol Supports multiple protocols such as LIN, RS-485, IrDA, smart card, etc.
Before transmitting, you need to know the baud rate. There is no need to know the transfer rate in advance.
Suitable for low speed communication Suitable for high speed communication.
Reduced energy footprint. Provides serial communications at high power consumption

The main difference between UART and USART is that UART only supports asynchronous communication whereas USART supports both synchronous and asynchronous. Here is a comparison between USART and UART:

RS232 AND UART

Logic levels represent operating voltage levels that the device can withstand to operate in a safe area. Here are the voltage levels for RS232 and TTL:

In most cases, RS232 levels range from -12V to +12V. For example, the ASCII value for the character “A” in RS232 is 65 and 41 in hexadecimal. So in 8-bit binary it is 0100 0001. Shown here is the representation of the RS232 logic levels for ASCII “A”.

TTL/CMOS LOGIC

UART works on TTL logic.

Initially, the serial line is in an idle state, commonly referred to as mark status (logical 1). Now the data transfer starts from the start bit (logical 0). In addition, 8 bits of data are sent one after the other over the serial line, with the LSB (Least significant bit) first. After the entire transfer is completed, there is a stop bit (logical 1).

ADVANTAGES AND DISADVANTAGES OF UART

  • The advantage of UART is that the protocol supports full duplex communication over two wires. In addition, no external timer is required for data transfer. It supports parity bit error checking, and the data length can be easily changed.
  • The main disadvantage is that it does not support multi-slave or multi-master configurations. And the data packet size is limited to 9 bits. UART is not suitable for complex serial communications with high power consumption.

SCOPE OF THE PROTOCOL

The serial debug port uses a UART driver to print data from outside. We can use this protocol to send and receive commands to and from embedded devices. Communication is also performed in GPS, GSM / GPRS modem, Wi-Fi chips and other modules working with UART. Used in mainframe access to connect different computers.

Ref: Link

Related Articles

Leave a Reply

Back to top button
error: Content is protected !!