stm32f4xx 单片机,采用外部晶振,晶振频率 8M,需要将晶振频率参数设置在软件中。
看到:stm32f4xx.h 文件中,涉及此处的内容为:
/**
* @brief In the following line adjust the value of External High Speed oscillator (HSE)
used in your application
Tip: To avoid modifying this file each time you need to use different HSE, you
can define the HSE value in your toolchain compiler preprocessor.
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
那么我们需要定义一个预编译宏 HSD_VALUE 来设置我们使用的 8M 频率参数,否则,将使用 stm32f4xx.h 中这里设置的 25M 频率,这样会使得程序下载下去后由于时钟同步问题根本无法运行。
最简单的做法,就是在工程的编译参数页面设置这个宏:

在 C/C++ Preprocessor Symbols 中,Define框里面,添加: HSE_VALUE=8000000
本文介绍如何在STM32F4XX单片机项目中正确配置外部8MHz晶振频率。通过设置预编译宏HSE_VALUE,确保程序能够正确识别晶振频率,避免因时钟配置错误导致的程序运行失败。

4581

被折叠的 条评论
为什么被折叠?



