1. What is baud rate? No matter what microcontroller it is, 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. The baud rate is consistent during data transmission between the two parties, which is the basic guarantee for successful communication. The following takes the STM32 microcontroller as an example to explain how to calculate the serial port baud rate. 2. STM32 baud rate related registers The STM32 microcontroller has only one register for setting the baud rate: the USART_BRR register, as shown in the figure below. The effective number of this register is 16 bits, the first 4 bits are used to store the decimal part, and the last 12 bits are used to store the integer part. After calculating the baud rate, fill in the value of this baud rate. The following describes how to calculate. 3. Baud rate calculation method The 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, Fck and Tx/Rx baud rate. These two are known, and USARTDIV is unknown. From the description of the formula, we can see that if USART1 is used, then Fck is PCLK2=72MHz, otherwise it is PCLK1=36MHz, and the parameter of Tx/Rx baud rate is known. We only need to calculate the value of USARTDIV and assign it to the USART_BRR register. Taking 115200 as an example, after transforming the formula, we get: USARTDIV = 72×1000000/(16×115200) = 39.0625. That is, write 39.0625 into USART_BRR. As mentioned above, the first 4 bits of USART_BRR store the decimal part, and the last 12 bits store the integer part. The decimal part DIV_Fraction = 0.0625×16 = 1 = 0x01; The integer part DIV_Mantissa = 39 = 0x27; Then USART_BRR = 0X271; The data sheet provides us with a data table: In this data sheet, the commonly used baud rate values have been calculated, and we can use them directly. However, if we want to make the baud rate calculation a parameter-passing function, For example: USART_INIT(uint_t 16 Baud), when calling, you only need to write USART_INIT(9600), USART_INIT(115200), so how should the program be written? 4. Program Implementation The following is the register version of the program. The first step of the program, line 45: first calculate USART_DIV, which is a variation of the previous formula; The second step of the program, line 46: Get the integer part of USART_DIV; Program step 3, line 47: Get the decimal part of USART_DIV; The fourth step of the program, line 48: Shift the integer part left by 4 bits, that is, store it in the last 12 bits of the BRR register; The fifth step of the program, line 49: combine the integer and the decimal part, that is, reassemble the first 4 digits and the last 12 digits; Program step 6, line 50: Assign the calculated value to the BRR register. In this way, a function with baud rate as a parameter is completed. From the above, it seems that the calculation of baud rate is not very difficult. |
Previous article:Detailed explanation of STM32 general timer
Next article:ARM Notes: GPIO Interface
Recommended ReadingLatest update time:2024-11-23 12:16
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- [Anxinke NB-IoT Development Board EC-01F-Kit] 1. Unboxing
- Should my country vigorously develop and invest in wireless charging technology for electric vehicles?
- Thinkpad Advanced Docking Station 40A80045CN Disassembly & Minor Modification (2)
- The matching principle between power amplifier and speaker
- [Mill Edge AI Computing Box FZ5 Review] Real-time Video Filling
- How to learn this new skill? I want to use the HAL library of STM32 and I want to use cubemx software
- Dissecting a small chip
- Characteristics of new Hall sensors and their applications in measurement and control
- TMS320C6748 Fixed-point and Floating-point DSP
- BlueNRG-LP sometimes cannot enter low power consumption