UART stands for Universal Asynchronous Receiver/Transmitter. It communicates asynchronously. UART can work with different types of serial protocols that involve transmitting and receiving serial data. UART is not like other protocols it is a physical circuit built-in microcontroller or a dedicated IC.
In old computer systems, devices like mouse or printer Uart was used for communicating although USB has replaced UART in recent devices still almost Microcontroller are using UART. In this blog, we will cover every concept about UART which will help you in better understanding this communication protocol.
Modes of communication in UART
UART has 3 different modes for communication:
- Simplex: Simplex data transmission means that data communication is one-way only.
- Full-duplex: Full–duplex data transmission means that data can be transmitted in both directions on a signal carrier, Simultaneously.
- Half-duplex: Half–duplex data transmission means that data can be transmitted in both directions on a signal carrier, but not at the same time.
HOW DOES IT WORK?
Communication between 2 UARTs
UART is a single-master, single-slave protocol, where one device is set up to communicate with only one partner. UART uses only two wires for communication, one is for transmitting data called Tx pin and one is for receiving data called Rx pin.
In UART, Master takes input from CPU or any other peripheral device in the parallel form then transmits the bits into serial form asynchronously to Rx [receiver], and then the slave or the receiving device transforms the data bits into parallel again with its controlling device. [ please refer blog1 for serial and parallel communication]
UART transmits data in the form of packets which includes a start bit, data frame, parity bit, and stop bit as shown in the following diagram.
- Start Bit
To start the transmission, the transmitter sends the 0 bit to the receiver or we can say that the clock pulse which is usually set at high voltage in a not transmitting state changes its voltage from high voltage to low voltage for one clock cycle. This clock pulse alert the receiver about the bits and then the receiver starts receiving the data bit by bit.
- Data Frame
Data Frame contains the main information about the data. Length of the data frame can vary between 5-8 bits if the parity bit is in use, if not then it can be 9 bits long as well.
The transmitter sends the data bit by bit to the receiver with a pre-defined baud rate. While transmitting data there is some delay which depends on the baud rate. The baud rate is a measure of the number of bits per second that can be transmitted or received by the UART.
- Parity bit
The parity bit is used for detecting the error in the main data.
How does parity work?
A number of 1’s needs to be counted in the data.
There are 2 types of parity bit:
- Even parity bit
In the case of even parity, for a given set of bits, the occurrences of bits whose value is 1 are counted.
If that count is odd, the parity bit value is set to 1, making the total count of occurrences of 1s in the whole set (including the parity bit) an even number.
If the count of 1s in a given set of bits is already even, the parity bit\’s value is 0.
- Odd parity bit
In the case of odd parity, the coding is reversed. For a given set of bits,
if the count of bits with a value of 1 is even, the parity bit value is set to 1 making the total count of 1s in the whole set (including the parity bit) an odd number.
If the count of bits with a value of 1 is odd, the count is already odd so the parity bit\’s value is 0.
- Stop bit
To stop the transmission, the transmission line goes from low to high voltage for 1-2 bits of the clock pulse.
STEPS OF UART TRANSMISSION
- The data bus of the CPU transmits the bits in parallel form to the transmitter Tx from the controlling devices which can be any of these CPUs of a microprocessor or a microcontroller, memory unit like a RAM or ROM, etc.
- As UART works asynchronously which means it doesn\’t have a clock signal for synchronizing so now it will use start and stop bits.
- The transmitter Tx adds these start, stop, and parity bits to the main data and converts its data frame into the serial form.
- The receiver Rx collects these bits by removing start, stop, and parity bits after checking if there is an error or not.
4.1 If an error is detected, then the receiver will ignore the received byte and request for retransmission of the same byte to the transmitter.
4.2 If not, it will receive it and so on.
5. Then again the receiver Rx converts the serial signal into the parallel form and then the transmitter Tx of the other UART transmits it to the control device via the data bus.
Now, how RS232 is connected to UART?
RS232 stands for Recommended Standard 232. A standard defining the signals between two devices, defining the signal names, their purpose, voltage levels, connectors, and pinouts.
This is a specific interface standard that allows for equipment interoperability. While two pieces of hardware may have UARTs, you don\’t know that they\’ll connect without damage, or communicate properly unless you know they have the same pinout and voltage standards, or include a converter or specially wired cable specific to the interconnection of these two specific devices.
To avoid the need for special converters or cables, the manufacturers may choose to follow the RS-232 standard. You know, then, that a standard RS-232 cable will connect the two.
Applications of UART
- Microcontroller to implement wireless data communication.
- Bluetooth and GPS modules.
- Transferring data through PC serial port.