UART Communication protocol
Published: 2023-09-07 15:26:14

Hi, I'm Rakshith M working as a junior software engineer at luxoft India. In this article I made my best effort to provide some of the aspects in UART Communication protocol and this is one of my interests

**Introduction**
UART is one of the most used device to device communication protocol UART means universal asynchronous receiver and transmitter protocol used to exchange data between personal computers and microcontroller board. UART is a hardware as well as protocol and UART is also called on-chip peripherals or device controllers.

**UART**
UART is basically designed for serial communication. UART is parallel in serial out and serial in parallel out on chip peripheral of microcontrollers. While transmitting data UART acts as parallel in serial out and while receiving data UART acts as serial in parallel out device

**Serial communication**
It is a process of sending one bit of data at a time. It uses a couple of wires so many companies prefer serial communication. This serial communication is used for long distance communication and low cost.

**Parallel communication**
It is a process of sending multiple bits at a time and it is used for short distance communication, the size is high, and cost is also high.

**Types of serial communication**
1.Synchronous serial communication
2.Asynchronous serial communication

**Synchronous serial communication**
This is a master and slave communication. In this, a common clock line used between transmitter and receiver. Some of the synchronous serial communication devices EEPROM (AT24C08), Real-time clock (DS1621), Digital accelerometer (ADXL345), ADC (ADS1115), OLED display.
Using one clock pulse one data bit can be transmitted. For every bit a new clock line must be generated this is called synchronization. In this master should not use high speed than slave.

**Asynchronous serial communication**
In this, a common clock line is not used between transmitter and the receiver. Here speed is the major parameter used for synchronization. That means in asynchronous serial communication transmitter and receiver speed must be same. If the speed is different slave will receive something and master will receive something.
Some of the devices are Bluetooth modem, XBee modem, FPS, RFID reader, GPS, GSM etc.

**Features of UART protocol**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nu66glqudgstr21pi7b3.png)
The UART protocol was designed by “Gordon bell” for long distance communication. It is a two wired communication protocol (Rx0 and Tx0). The main purpose of a transmitter and receiver line for each device is to transmit and receive serial data intended for serial communication. UART can transfer data in both transmitting and receiving sections. It is full duplex asynchronous serial communication protocol and UART is designed for peer-to-peer communication.
The maximum speed of UART is up to 1MBPS. The UART can send only 1byte of data into 1 data frame. Data transfer direction is always from LSB to MSB
The idle condition of UART is when it is connected to any device the transmitter node is 1 (3.3V) and receiver node is also 1 (3.3V).  After connecting the transmitting section will execute after receiving section after that baud rate settings should be done.

**How data transmits in UART**
Here the mode of transmission is in the form of packets. The sockets which are connected to transmitter and the receiver are in the form of packets and control the physical hardware’s and the packets consists of start bit, data bit, parity bit, stop bit.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2h2vzkarwmd3sfgbj9q.png)

**Start bit:** the transmission of UART starts with high voltage when it is not transmitting data. For transmitting the data, the voltage level should be changed from high to low. When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at the frequency of the baud rate. 

**Data bit:** The UART can send 8 bits of data at a time. The data is sent from most significant bit to least significant bit.

**Parity bit:** parity is the error checking method used in UART. When an error is detected the parity bit becomes one and it transmits error frame.

**Stop bit:** Stop bit used to stop the data transmission.

**Transmitting section of UART**
Idly Tx buffer is zero when we write any data into the registers that is stored in Tx buffer and internally Tx flag becomes one and after the data is transmitted from Tx to Rx. When data is transmitted when Tx buffer becomes empty, then Tx flag becomes zero indicates bus is free. After that it can transfer another data, before sending another data we must clear Tx flag. When the data is transmission is ongoing if we write another data its an error and it transfers error frame by setting parity bit.

**Receiving section of UART**
When data is received it is stored in the receiver buffer. Idly receiver buffer is zero when data is received it is filled with data and Tx flag becomes one here idly Tx flag is also zero. After receiving the data, we must read that register data to receive another data. Here the start and stop bit is not stored in Rx buffer it is only for starting and ending.
Baud rate setting
Baud rate means number of bits transmitted/received per second including start and stop bits. If the baud rate is 9600 bps the UART can send 960 bytes of data per second. Here one data frame is equal to ten bits (8bits + 1 start + 1 stop).

**Applications of UART**
1.	Transmitting and receiving UART’s must be set to same bit, parity and stop bits for them to function properly.
2.	Serial ports used in personal computers and embedded systems use UART’s. These devices use the CPU to sample the state of data transmissions. However, the UART chip can be omitted to save money and space in devices.
3.	UART’s were more commonly used a while back in personal computers and their peripherals, such as a mouse and keyboard. However, they have been replaced with USB in recent times.

**Conclusion**
The Universal Asynchronous Receiver Transmitter protocol is a straightforward yet effective means of serial communication between two devices. Its ease of implementation, adaptability, and efficiency make it an excellent choice for a wide range of electrical and embedded system applications.