Serial Communication Baud Rate Calculation Method of STM32 Single-chip Microcomputer

1. What is the baud rate

No matter what the microcontroller, when using serial communication, there is a very important parameter: baud rate. What is baud rate: baud rate is the number of bytes transmitted per second. In the process of data transmission, both parties have the same baud rate, which is the basic guarantee for successful communications. The following STM32 microcontroller as an example to explain the serial port baud rate calculation method.

2. STM32 baud rate related registers

There is only one register for setting the baud rate of the STM32 microcontroller: the USART_BRR register, as shown in the figure below.

The effective number of bits in this register is 16 bits. The first 4 bits are used to store the fractional part and the last 12 bits are used to store the integer part. After the baud rate is calculated, the value can be filled in at this baud rate. Here's how to calculate.

3. The baud rate calculation method

STM32 data sheet gives the calculation method, there is a formula, as shown below:

In this formula, there are three variables, two of which we know, two of which are FCK and Tx/Rx baud rates, and USARTDIV is unknown. It can be seen from the description of this formula that if USART1 is used, then Fck is PCLK2=72MHz, otherwise it is PCLK1=36MHz, and this parameter of Tx/Rx baud rate is known. It is only necessary to calculate the USARTDIV value assigned to the USART_BRR register. Taking 115200 as an example, the formula is obtained after deformation: USARTDIV = 72×1000000/(16×115200) = 39.0625. Write 39.0625 to USART_BRR.

As mentioned earlier, the first 4 bits of the USART_BRR store the fractional part, and the last 12 bits store the integer part.

That fractional part DIV_Fraction = 0.0625 × 16 = 1 = 0x01; that integer part DIV_Mantissa = 39 = 0x27; that USART_BRR = 0X271;

The data sheet provides us with a data sheet:

On this data sheet, the commonly used baud rate has been calculated and we can use it directly. But if we want to make the baud rate calculation a pass parameter function, such as: USART_INIT(uint_t 16 Baud), only USART_INIT(9600), USART_INIT(115200) need to be written in the call. How should the program be written? ?

4. The realization of the program

The following is a register version of the program.

The first step of the program is 45 lines: first calculate the USART_DIV, this is the deformation of the previous formula; the second line of the program 46: get the integer part of the USART_DIV; the third step of the program 47: get the fractional part of the USART_DIV; the fourth step of the program 48 Line: Move the integer part to the left by 4 bits, ie, store it in the last 12 bits of the BRR register. The fifth step of the program is 49 lines: Combine the integer and decimal parts together, that is, the first 4 bits and the last 12 bits are recombined; program sixth Step 50: Assign the calculated value to the BRR register.

Such a function that takes the baud rate as a formal parameter is completed. From the above point of view, the baud rate calculation does not seem to be very difficult.

9H Flexible Glass Screen Protector

This kind of Flexible Glass Screen Protective Film is made of nano-glass material and is an indispensable device for people who often drop their mobile phones. The Flexible Protective Film can be perfectly fixed on the mobile phone to completely protect the mobile phone screen to prevent scratches and cracks on the edge of the mobile phone screen.

The surface hardness is 9H hardness. Sharp objects (such as knives and keys) will not scratch the surface.

The high transparency of 0.22mm ensures that you can view all screen content clearly and clearly, while providing unique touch screen sensitivity.

The Screen Protection Film has an "oleophobic and waterproof" coating that prevents dust and fingerprint smudges and ensures that it can be easily removed.

In case the screen is damaged, the Screen Protector will break into small pieces that are not sharp, which is much safer than other glass screen protectors on the market.

If you want to know more about 9H Flexible Glass Screen Protector products, please click product details to view the parameters, models, pictures, prices and other information about 9H Flexible Glass Screen Protector products.

Whether you are a group or an individual, we will try our best to provide you with accurate and comprehensive information about 9H Flexible Glass Screen Protector!


9H Flexible Glass Screen Protector, 9H Screen Protector, 9H Flexible Protective Film, Flexible Protective Film

Shenzhen Jianjiantong Technology Co., Ltd. , https://www.hydrogelprotectivefilm.com

Posted on