UART
stands for universal asynchronous receiver and transmitter. UART is an
asynchronous half duplex communication protocol. It is called universal because
of configurable parameters such as speed, frame format and can be configured to meet the needs of a given
communication requirement. There is no clock signal between transmitter and
receiver. Both transmitter and receiver may work on different clock speed. Two devices communicate with each other
through three signals TX, RX and GND as shown in figure below:
Device1
Tx will connect with Device2 RX and Device1 RX will connect with Device2 TX and
both devices GND will be common. It is
half duplex communication protocol which share the same register for data
transmission and register. So when using UART it should be kept in minds that
you should transmit and receive simultaneously. At transmitter side UART done
parallel to serial conversion of the data which is received from the CPU and at
receiver end UART perform serial to parallel conversion on the data received
through serial communication.
Frame
Structure
In
UART data is transferred in a proper frame structure. UART frame consist of
data bits and control bits. UART frame consists of following data:
·
Start bit
·
8 or 9 data bit
·
Parity Bit (optional)
·
1 or 2 stop bit
Figure
below show the data frame with 8 data bit 1 start bit and 1 stop bit:
The
parity bit in UART data frame is optional.
The parity can be even or odd. The UART peripheral calculates the number
of 1s present in the transmission. If the parity is configured to even and the
number of 1’s is even then the parity bit is set zero. If the number of 1s is
odd, the parity bit is set to a 1 to make the count even. If the parity is
configured to odd, and the number of 1s is odd, then parity bit is set to 0.
Otherwise it is set to 1 to make the count odd. At receiver end UART check
remove this bit from the data. START bit always will be 0 and STOP bit always
will be 1.
When
there is no communication TX pin remains high. When Communication starts
Transmitter pulls the TX pin low (START bit). After data bit STOP bit will be
transmitted. Every Bit will be of certain duration. This depends on the
communication Baud rate selected.
After
getting START bit (Sense LOW on RX pin) receiver samples in the middle of every
period and save data to UART DATA REGISTER and also give information to CPU by
setting flag in register or by interrupt or CPU if enabled. Receiver also verifies the Parity Bit and
STOP bit. If there is any framing or parity receiver notifies to CPU by setting
error bits in UART STATUS register.
Figure
show below the transmission of Char ‘D’ without parity bit and 1 stop bit.
Char
‘D’ Decimal equivalent is 68 and hex decimal equivalent is 0x44.
Binary
equivalent will be B”01000100”.
What is BAUD RATE?
BAUD
rate defines the data communication rate in UART communication. Baud rate
specified in bps(bits per second). So baud defines how many bits may be
transferred in one second from one device to another device. For example if
Baud rate defines as 9600 bps. It means 9600 bits can be transferred from one
device to another device. For proper communication receiver and transmitter
should be configured to same baud rate. Otherwise receiver will receive abrupt
data.
One
bit period at 9600 baud rate will be = 1/9600 sec = 104.16 usec
1
Byte with 1 start bit and 1 stop bit transmission time will be = 10*104.16 usec = 1.04 ms
So
it takes 1.04 ms to transmit one byte from one device to another device.