UART
1.0 What is UART
UART stands for Universal Asynchronous Receiver and Transmitter it is serial communication protocol that sends parallel data, in a serial and asynchronous way.
Serially here, means data are being transferred bit by bit i.e. one after the other compared to parallel transmission where all data bits are transferred at once.
Asynchronous means that the receiver and transmitter do not share a common clock, i.e. they are not being synchronized compared to other synchronous transmission like SPI as we would see in another tutorial.
It is also known as Serial port, Com port, RS-232.
1.1 UART configuration parameters
To configure UART some parameters need to be configured.
1. Baud rate – This is the number of bits sent per seconds. Both Tx and Rx will agree at the rate of data bits to be sent per second. Standard baud rates include
300bps, 1200bps, 2400bps, 4800bps, 9600bps, 19200bps, 38400bps, 576bps, 115200bps.
2. Number of data bits – The Tx and Rx also have to decide the size of each data frame whether 7 or 8bits or more.
3. Parity bit – Parity bit is used to check for single bit error or errors of odd number of bits. It is configured to be either on (i.e. parity bit is transmitted) or off (No parity bit in transmission)
4. Stop bit – The stop bit is also configured to be either 1, 0 or 2.
5. The transmission can also be configured as simplex (Where data is sent in one direction only), half duplex (Data is sent in both direction but one at a time) or full duplex (Both sides can send and receive data simultaneously).
A typical UART data is transmitted serially in groups called frame as shown below
1.2
In the above diagram, initially before any transmission the data lines are held high or 1,
this is indicated by the two points marked line idling in the diagram above, it means no data is being transmitted.
To send a data a low or 0 is first transmitted to let the receiver know that data is being sent this low bit is called the start bit.
This start bit is then followed by the actual data bits to be sent which can be 7 or 8 or other values depending on the configuration already agreed by the Tx and Rx.
The first bit of the data bit to be sent is usually the LSB (least significant bit), by this way the receiver also receives it first. The next bit is the optional parity bit. It depends on the configuration between Tx and Rx whether the parity bit should be present.
Then lastly, the stop bit and then the line goes back to high till next data transmission.
The parity could be even or odd parity. The even parity bit is a zero when there are even number of 1`s and a 1 when there are odd number of 1`s. While the Odd parity bit is a 0 when there are odd number of 1`s and a zero when there are even number of 1`s. This is shown in the table below.
1.3 Example Calculation
Assume a data transmission requires 19200 baud to send 8 data bits with one start bit, no parity and one stop bit
• What is the frame size?
• What is the data throughput or bandwidth of transmission in Kbps (Kilobits per seconds) and KB/s (Kilobyte per second)?
Solution --
• 1 start bit + 8 data bits + 1 stop bit = 10 bits
It takes 10 bits to send 8 bits (1 byte) of data at 19.2 kbps. Frame size is
10bits.
• 8 data bits / 10bits (frame size) * 19200 =
15.36 kbps
• How many KB (kilobytes) per second is this? –
15.3kbps = 15300bits/s
*8 bits =1 byte
15300bits/s = 1912.5 bytes/s
*1,024 bytes = 1 KB
1912.5 bytes/s =
1.875 KB/s