|
STM32L系列RTC使用HSE/16作为时钟源遇到的问题和解决
[复制链接]
由于种种原因,所用的硬件没有LSE的晶振,在使用RTC模块的时候,一开始呢使用的是LSI作为时钟源,在单板上调试好后对时间精度要求不高的情况下倒是可以使用,但是LSI的时钟是一个范围值,导致每个板子的RTC_SynchPrediv的值是不一样的,就没有办法作为量产的设置。所以就考虑了用HSE作为时钟源(产品对精度要求一般),看了一些手册RTC的时钟源不能超过1M所以就对HSE进行了16分频,结合ST的库函数(V1.3.0),修改了RCC_RTCCLKConfig()中的参数改为RCC_RTCCLKSource_HSE_Div16,然后修改了RTC_InitStruct->RTC_SynchPrediv,RTC_InitStruct->RTC_AsynchPrediv,修改之后在尝试时间速度很快,那么问题出在哪里呢?- /**
- * [url=home.php?mod=space&uid=159083]@brief[/url] Configures the RTC and LCD clock (RTCCLK / LCDCLK).
- * @note As the RTC clock configuration bits are in the RTC domain and write
- * access is denied to this domain after reset, you have to enable write
- * access using PWR_RTCAccessCmd(ENABLE) function before to configure
- * the RTC clock source (to be done once after reset).
- * @note Once the RTC clock is configured it can't be changed unless the RTC
- * is reset using RCC_RTCResetCmd function, or by a Power On Reset (POR)
- * @note The RTC clock (RTCCLK) is used also to clock the LCD (LCDCLK).
- *
- * @param RCC_RTCCLKSource: specifies the RTC clock source.
- * This parameter can be one of the following values:
- * @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
- * @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
- * @arg RCC_RTCCLKSource_HSE_Div2: HSE divided by 2 selected as RTC clock
- * @arg RCC_RTCCLKSource_HSE_Div4: HSE divided by 4 selected as RTC clock
- * @arg RCC_RTCCLKSource_HSE_Div8: HSE divided by 8 selected as RTC clock
- * @arg RCC_RTCCLKSource_HSE_Div16: HSE divided by 16 selected as RTC clock
- *
- * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
- * work in STOP and STANDBY modes, and can be used as wakeup source.
- * However, when the HSE clock is used as RTC clock source, the RTC
- * cannot be used in STOP and STANDBY modes.
- *
- * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
- * RTC clock source).
- *
- * @retval None
- */
- void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)
- {
- uint32_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));
- //logout("hse on =%d\r\n",RCC->CR&RCC_CR_HSEON);
- if ((RCC_RTCCLKSource & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE)
- {
- /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */
- tmpreg = RCC->CR;
- /* Clear RTCPRE[1:0] bits */
- tmpreg &= ~RCC_CR_RTCPRE;
- /* Configure HSE division factor for RTC clock */
- tmpreg |= (RCC_RTCCLKSource & RCC_CR_RTCPRE);
- /* Store the new value */
- RCC->CR = tmpreg;
- }
-
- RCC->CSR &= ~RCC_CSR_RTCSEL;
-
- /* Select the RTC clock source */
- RCC->CSR |= (RCC_RTCCLKSource & RCC_CSR_RTCSEL);
- }
复制代码 然后就一直在找,将RTC_InitStruct->RTC_SynchPrediv,RTC_InitStruct->RTC_AsynchPrediv这两个值调节到了最大,还是快,然后只能默默的对着数据手册找呀找呀,终于找到了这么一句话:
然后就看看设置时是否对这个值进行了处理,果然没有。。。。
又害怕在这个RCC_RTCCLKConfig()函数中进行修改会影响其他部分,然后只能默默的设置时钟的时候就直接对这个寄存器操作进行了相关位的操作。改完之后就很正常了。不过像这样RTC使用HSE的估计也很少,不过也说明那个库函数还是不是很严谨的。大家如果遇到类似的情况,希望可以帮到大家。也可能说的不对,不详细的,也欢迎指导指正
|
|