当前位置:网站首页>Gd32f4 (6): serial port garbled caused by crystal oscillator

Gd32f4 (6): serial port garbled caused by crystal oscillator

2022-07-18 21:08:00 Little Grey Bear

GD32F4(6): Crystal oscillator causes serial port garbled

1. System environment

  • System :win10

  • IDE:keil5

  • Development board :GD Official evaluation board GD32450Z_EVAL

  • User manual version :GD32F4xx_yonghushouce_Rev2.6.pdf

  • Standard library version :GD32F4xx_Demo_Suites_V2.5.0

2. The serial port of the development board is garbled

The official development board crystal vibrators are 25M Of , When designing by yourself, you may use external crystal oscillators with other values , You need to design your own clock program , Fortunately GD There are many official programs , You change the macro by , You can switch back and forth under different crystal oscillators , as follows :
 Insert picture description here
you 're right , In this way, it is set to 200M 了 , Please refer to my other article for the specific principle :GD32F4(5):GD32F450 The clock is configured as 200M process analysis

Now the system is 200M you 're right , But the peripheral does not know the current clock of the system , That will lead to an error in the initialization clock of the peripheral , For example, when using serial port , You will find that the data is garbled , This is because there is a macro that defines the clock that needs to be modified , as follows :
 Insert picture description here

explain : When using peripherals , Peripheral clock initialization will call rcu_clock_freq_get(rcu_clock_freq_enum clock) Get clock , Here's the picture :
 Insert picture description here
This function will read the configured crystal oscillator clock and the registers related to the clock configuration , Work out each bit Clock delay required , When the calculated delay is equal to the real delay , There will be no garbled code .

原网站

版权声明
本文为[Little Grey Bear]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/199/202207161825294547.html