Follow+Star PublicAccount, don’t miss exciting content
Reference Source | Renesas Embedded Encyclopedia
Modern microcontrollers are increasingly resource-rich, with multiple integrated serial ports, and their key functionalities are becoming more powerful.
Some applications may require automatic baud rate detection for serial communication. Today, we will discuss the common principles of automatic baud rate detection at the MCU level, along with examples from MCUs.
Common Principles of Automatic Baud Rate Detection
The underlying principle of automatic baud rate detection (Auto Baud Rate Detection, ABR) is mainly based on the transmission characteristics of data in serial communication and the interaction mechanisms between devices. Here are several common principles for automatic baud rate detection.
Start and Stop Bit Detection Method:
Principle: In serial communication, each data packet begins with a start bit (usually 0) and ends with one or more stop bits (usually 1). By detecting the time intervals between these two bits, the baud rate can be calculated.
Specific Pattern Detection Method:
Principle: The sending device transmits a series of bytes with a specific pattern (such as a fixed byte sequence or pattern), and the receiving device attempts to receive and detect these patterns at different baud rates. When data matching the sending pattern is detected, the current baud rate can be determined.
Baud Rate Scanning Method:
Principle: The sending device sends a scanning command containing multiple different baud rates during the initialization phase. The receiving device automatically detects and matches the closest baud rate upon receiving these commands.
Periodic Signal Detection Method:
Principle: This method uses the periodic changes of the signal for baud rate detection. By analyzing the frequency and periodic characteristics of the signal, the baud rate can be inferred.
MCU Hardware Automatic Baud Rate Detection
Many newly released MCUs on the market now have automatic baud rate detection capabilities. Here, we will take the Renesas RA series microcontroller as an example and explain the configuration of automatic baud rate detection in serial communication using e2 studio.
1
UART1 Configuration
The configuration of UART1 only needs to be done according to application requirements, but it is essential to ensure that the selected RXD pin is multiplexed with IRQ for software switching. Since this is for baud rate adaptation, the configuration regarding Baud in the property page can be ignored.

2
GPT Configuration
Since it is necessary to measure the time interval of the start bit using a timer, you can choose GPT/AGT in one-shot/Periodic mode and leave enough margin in the Period value to ensure that the start bit does not overflow at low speeds.
3
P402 Pin Configuration as IRQ4
Change the default RXD pin (P402) of the SCI1 serial port to IRQ4 and add an interrupt entry function.

In the interrupt entry function, first check if a falling edge trigger has occurred, then start the timer. After the next interrupt occurs, stop the timer and obtain the timer count value. By dividing this value by the known system clock parameters, the exact baud rate can be obtained.

4
Baud Rate Calculation and Related Register Configuration
After obtaining the actual baud rate value, the relevant equations in the hardware manual can be used to derive the required values for several control baud rate registers (brr, semr, cks, etc.), and the calculated values should be modified in the global variable structure of FSP SCI1 (g_uart1_baud_setting).

5
Change P402 Pin Configuration to UART-RXD
Then change the P402 pin to UART function and start the UART_Open() function to set the baud rate configuration flag.

6
Thus, the main function can directly send and start receiving data using the detected baud rate.


The above methods allow for simple and quick baud rate detection, calculation, and configuration through low-level register configuration. With this approach, as long as the chip’s system clock meets the range requirements, any non-standard or extremely high/low baud rates can also be detected and configured for use.
———— END ————
How to Build a Development Team for Embedded Projects?

Industrial DC Brushless Fan Solutions Based on MCU

Principles and Methods of OLED Display Based on MCU via I²C