Getting Started with UART: UART Protocol

Table of Contents

  1. What is UART Protocol?
  2. UART PIN Config
  3. UART Packet Format
  4. UART Data Commuincation
  5. UART Clock Speed
  6. Conclusion

1.What is UART Protocol?

UART (Universal Asynchronous Receiver/Transmitter) is a communication protocol commonly used in microcontrollers and other embedded systems. It allows for serial communication, enabling the transfer of data between two or more devices. Two main components in UART are: a transmitter and a receiver. The transmitter converts parallel data from a microcontroller or computer into a serial stream of bits, while the receiver converts the serial stream of bits back into parallel data. The data is transmitted in the form of packets called frames, which consist of a start bit, data bits, optional parity bit, and stop bits.

2.UART PIN Config

The push-pull configuration in UART hardware refers to the way in which the TX and RX lines are driven. In a push-pull configuration, each line is connected to a pair of transistors: one transistor is responsible for pulling the line low (logic 0), while the other transistor is responsible for pulling the line high (logic 1).

push  pull GPIO config

When data is transmitted from the TX line, the UART hardware first sends a start bit, which is a low-level signal. The push-pull configuration of the UART hardware then pulls the line low using one of the transistors. The data bits are then transmitted one at a time, with the push-pull configuration switching between pulling the line low and high to indicate a 0 or 1 bit, respectively. Finally, one or more stop bits are sent at the end of the frame.

On the receiving end, the push-pull configuration works in reverse. When the RX line receives a start bit, the UART hardware pulls the line low using one of the transistors. It then samples the incoming data bits at regular intervals to determine whether each bit is a 0 or 1. Once all the data bits have been received, the UART hardware raises the RX line high using the other transistor to signal the end of the frame.

3.UART Packet Format

As mentioned above, UART communication involves transmitting data in the form of frames, with each frame consisting of a start bit, data bits, optional parity bit, and stop bit. Details of the frame is as below: 

    • The Start Bit: The start bit is a logic low (0) signal that indicates the beginning of the data frame. It is used to alert the receiver that data is about to be transmitted. 
    • The Data Bits: The data bits contain the actual data being transmitted. The number of data bits in a frame can vary depending on the application, with 8 bits being the most common. The data bits are transmitted least significant bit first, and can represent any type of information, such as ASCII characters or binary values.
    • The Parity Bit: The parity bit is an optional bit that is sometimes included in the data frame to detect errors during transmission. There are two types of parity: even and odd. In even parity, the parity bit is set to ensure that the total number of 1s in the data bits (excluding the parity bit) is even. In odd parity, the parity bit is set to ensure that the total number of 1s in the data bits is odd. If a bit error occurs during transmission, the parity check will fail and the receiver will know that the data is corrupt.
    • The Stop Bit: The stop bit is a logic high (1) signal that indicates the end of the data frame. It is used to signal the receiver that the data transmission is complete. The stop bit can be one or two bits long, depending on the UART configuration.UART complete frame

4.UART Data Communication

UART data communication can occur in two ways: synchronous and asynchronous. In synchronous communication, both the transmitter and receiver use a common clock signal to synchronize data transmission. In asynchronous communication, however, there is no common clock signal, and the start and stop bits are used to synchronize data transmission.

Asynchronous communication is the most common method used in UART data communication, and is generally considered more flexible and reliable than synchronous communication. Asynchronous communication allows for variable length data frames and can be used with a wide range of data rates. As shown below, The start bit indicates the start of a new frame and is always a logic low (0) signal. The data bits are the actual data being transmitted, with each bit being sent one after the other. In the given scenario, there are 8 bits of data and 1 parity bit. The stop bit is the final bit in the frame and is always a logic high (1) signal. The stop bit indicates the end of the frame and allows the receiving device to detect when the frame has ended.

uart frame

5.UART Clock Speed

The clock speed of a UART is determined by the baud rate, which specifies the number of bits transmitted per second. For example, a baud rate of 9600 means that 9600 bits are transmitted per second. The clock speed is calculated by dividing the system clock frequency by the baud rate.

Clock speed is important because it affects the reliability and accuracy of data transmission. If the clock speed is too low, the data may be transmitted too slowly, resulting in delays or even data loss. On the other hand, if the clock speed is too high, the data may be transmitted too quickly, leading to errors or data corruption.

uart clock

It's important to note that the clock speed of the UART must be the same on both the transmitting and receiving devices in order for communication to be successful. This means that both devices must be set to the same baud rate.

6.Conclusion

In conclusion, UART communication is a widely used protocol in microcontrollers and other embedded systems due to its simplicity and reliability. It allows for serial communication between devices without the need for a clock signal, making it easier to implement in hardware. While USART offers additional features, UART remains a popular choice for many applications due to its simplicity and versatility. Understanding the basics of UART communication is essential for anyone working with microcontrollers and embedded systems.