你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

st-img
chrome
st-img
firefox
st-img
safari
st-img
ie8及以上
shequ.stmicroelectronics.cn
  • ST意法半导体官网
  • STM32中文官网
  • ST全球论坛
登录/注册
  • 首页
  • 技术问答
  • 话题
  • 资源
  • 创客秀
  • 视频
  • 标签
  • 积分商城
  • 每日签到
天堂隔壁

天堂隔壁

 

回答数 0 关注数 0
关注 私信
  • 动态99
  • 提问
  • 回答0
  • 创客秀 0
  • 分享 0
  • 关注0
10 回答

关于STM32L476时钟设置使得串口波特率加倍问题

STM32L4
nyszx nyszx 回答时间: 2018-1-19 16:40

1、首先对楼主的一些建议:想要外设测试样例,不要去网上找,网上的根本没保证,就简单最可靠的就是去STM32CubeMX库里面找每个系列都对应的官方开发板,都有外设的驱动样例。以STM32L476RG-Nucleo为例,打开里面有很多代码可以学习参考: 各种外设驱动样例: 2、其次,楼主只贴了RCC代码,无法明确问题原因,只能帮楼主分析下,如果使用完整的HAL驱动的话,串口初始化,会执行底层的HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)函数,里面会获取UART时钟源,并根据时钟源去查找系统当前时钟,进而进行波特率等更时钟相关的寄存器设置,而程序是如何知道系统当前时钟的呢?答案是stm32l4xx_hal_conf.h中定义的,并不是神奇的软件能够自动识别硬件得到的,只是根据RCC寄存器值获取分频、倍频等参数状态+基础时钟(HSE\HSI\LSE\LSI等)计算出来的,关键的就在这些定义上,如: /* ########################## Oscillator Values adaptation ####################*/ /**   * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.   *        This value is used by the RCC HAL module to compute the system frequency   *        (when HSE is used as system clock source, directly or through the PLL).   */ #if !defined  (HSE_VALUE)   #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined  (HSE_STARTUP_TIMEOUT)   #define HSE_STARTUP_TIMEOUT    ((uint32_t)100)   /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /**   * @brief Internal Multiple Speed oscillator (MSI) default value.   *        This value is the default MSI range value after Reset.   */ #if !defined  (MSI_VALUE)   #define MSI_VALUE    ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ /**   * @brief Internal High Speed oscillator (HSI) value.   *        This value is used by the RCC HAL module to compute the system frequency   *        (when HSI is used as system clock source, directly or through the PLL).   */ #if !defined  (HSI_VALUE)   #define HSI_VALUE    ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /**   * @brief Internal Low Speed oscillator (LSI) value.   */ #if !defined  (LSI_VALUE) #define LSI_VALUE  ((uint32_t)32000)       /*!< LSI Typical Value in Hz*/ #endif /* LSI_VALUE */                      /*!< Value of the Internal Low Speed oscillator in Hz                                              The real value may vary depending on the variations                                              in voltage and temperature.*/ /**   * @brief External Low Speed oscillator (LSE) value.   *        This value is used by the UART, RTC HAL module to compute the system frequency   */ #if !defined  (LSE_VALUE)   #define LSE_VALUE    ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ #endif /* LSE_VALUE */ #if !defined  (LSE_STARTUP_TIMEOUT)   #define LSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for LSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /**   * @brief External clock source for SAI1 peripheral   *        This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source   *        frequency.   */ #if !defined  (EXTERNAL_SAI1_CLOCK_VALUE)   #define EXTERNAL_SAI1_CLOCK_VALUE    ((uint32_t)48000) /*!< Value of the SAI1 External clock source in Hz*/ #endif /* EXTERNAL_SAI1_CLOCK_VALUE */ /**   * @brief External clock source for SAI2 peripheral   *        This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source   *        frequency.   */ #if !defined  (EXTERNAL_SAI2_CLOCK_VALUE)   #define EXTERNAL_SAI2_CLOCK_VALUE    ((uint32_t)48000) /*!< Value of the SAI2 External clock source in Hz*/ #endif /* EXTERNAL_SAI2_CLOCK_VALUE */ 复制代码比如如果你使用外部8M高速晶振,你需要修改HSE_VALUE为8000000,假设你实际使用的外部晶振为12M,而你的HSE_VALUE仍为8000000,系统也会跑起来,但是通过HAL_RCC_GetSysClockFreq()等获取时钟的函数得到的值就不对了。也许这就是问题原因的所在,希望楼主能解决此问题。

赞0
10 回答

自己下载的STM32F4的DFP.PACK安装出错

STM32F4
bodaohjd_300978 bodaohjd_300978 回答时间: 2018-7-10 18:02

帮忙顶

赞0
16 回答

STM32F107VCT6串口发送数据乱码

STM32F1
废鱼 废鱼 回答时间: 2015-5-28 11:25

因为你把那个去掉了.这里屏蔽了.即使不定义,这里判断走的是else分支. //#ifdef STM32F10X_CL    // #define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ //#else   #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ //#endif /* STM32F10X_CL */ #endif /* HSE_VALUE */

赞0
天堂隔壁 天堂隔壁


阅读作者更多的帖子

所在话题

参与活动

  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16