Asynchronous communication mechanism for UART communication

UART (Universal Asynchronous Receiver/Transmitter) is a commonly used serial communication protocol that is widely used in communication between microcontrollers or various embedded devices. This article will introduce in detail the basic principles, working modes, baud rate calculation and common usage methods of UART communication to help people with certain microcontroller development capabilities better understand and apply UART communication.

UART communication is an asynchronous serial communication method. Its basic principle is to transmit binary data bits through data lines. The UART communication system is mainly composed of two parts: the sending end and the receiving end, and data is transmitted between them through data lines. The sending end converts the data to be sent into parallel signals, then converts the parallel signals into serial signals through the driving circuit, and sends the serial signals to the data line through the sending circuit. The receiving end restores the signal on the data line to a parallel signal through the receiving circuit, and then converts the parallel signal into the original data bit through the decoding circuit.

UART communication adopts asynchronous communication method, that is, data transmission is carried out through data lines between the sending end and the receiving end. In asynchronous communication, the sender and receiver do not need to be active at the same time. Instead, the start and stop bits are used to identify the start and end of the data frame. Specifically, when the sending end generates the start bit, it sends one data bit; then it waits for the starting bit of the receiving end. If the start bit is received, it continues to send the next data bit; if the start bit is not received, then It is considered that the data frame transmission failed. Similarly, when the receiving end generates a stop bit, it sends a check bit; then it waits for the stop bit from the sending end. If the stop bit is received, the data frame transmission is considered successful.

UART baud rate

The baud rate represents the number of bits of binary data transmitted through the line per unit time, usually expressed in bps (bits per second). For example, if the baud rate is 9600bps, 9600 bits of data can be transmitted per second.

The baud rate of serial port transmission data is generated by the clock system of the microcontroller, so it has a mathematical relationship with the system clock of the microcontroller.

Baud rate = (16 * clock frequency) / (32 * sampling time) + (1 * clock frequency) / (32 * sampling time) – (1 * clock frequency) / (64 * sampling time)

Among them, the sampling time refers to the time interval from the last starting bit to the current starting bit. For example, if the sampling time is 10ns, the baud rate is 9600bps.

Common baud rates are 2400, 4800, 9600, 19200, 38400, 57600, 115200… They are all integer multiples of 2400, so different baud rates can be generated through frequency dividers. Although today’s microcontrollers have different frequencies, the common ones are 32MHz, 48MHz and 144MHz. Usually they have an external system clock that provides a basic clock frequency (such as 1MHz) for the peripheral devices of the microcontroller. The UART baud rate is also generated from this clock. Generate clock signal.

It should be noted that in actual use, the clock frequency may be affected by some factors, such as crystal oscillator drift, power supply noise, etc. Therefore, in order to ensure the accuracy and reliability of data transmission, it is recommended to use an external crystal oscillator or clock generator and calibrate and compensate it when designing a UART communication system.

Asynchronous communication mechanism for UART communicationultima modifica: 2023-10-27T05:03:20+02:00da rubberantenna
Reposta per primo quest’articolo