STM32
直播中

王玉兰

8年用户 1386经验值
私信 关注
[问答]

使用RTC ALARM A闹钟唤醒STM32F030c8t6和WAKEUP引脚外部唤醒 ,唤醒以后进行校准时间有偏差正常吗?

使用了RTC ALARM A闹钟唤醒STM32F030c8t6和WAKEUP引脚外部唤醒 ,当外部唤醒以后进行校准时间,发现一小时能差8分钟。下面是我的RTC配置 和系统时间配置

  • oid RCC_Configuration(void)
  • {
  •         /* RCC system reset(for debug purpose) */
  •     RCC_DeInit();
  •         RCC_LSICmd(ENABLE);
  •     while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);//等待HSI就绪
  •     RCC_HCLKConfig(RCC_SYSCLK_Div1);//配置AHB Prescaler为1(根据cubemx的时钟图看的)-->得到HCLK 8 M
  •     RCC_PCLKConfig(RCC_HCLK_Div1);//配置APB1 Prescaler 为1 得到 PCLK1 = 8M-->同时APB1 外设时钟和和APB1上的定时器->8Mhz

  • //    RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_8);//HSI RC(8MHZ) /2 * 8->PLLCLK = 32 Mhz
  • //    RCC_PLLCmd(ENABLE);
  • //    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//将 PLLCLK作为系统时钟
  •     RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);//将内部时钟作为系统时钟 ->8mhz
  •      /* 使能APB1时钟 */
  •     RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//使能 PWR时钟
  • }


  • void RTC_Configuration(void)
  • {
  •         /* Enable the PWR clock */
  •         RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  •         /* Allow access to RTC */
  •         PWR_BackupAccessCmd(ENABLE);

  •         #if defined (RTC_CLOCK_SOURCE_LSI)  /* LSI used as RTC source clock*/
  •         /* The RTC Clock may varies due to LSI frequency dispersion. */
  •         /* Enable the LSI OSC */
  •         RCC_LSICmd(ENABLE);

  •         /* Wait till LSI is ready */
  •         while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  •         {
  •         }
  •         /* Check if the StandBy flag is set */
  •         if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
  •         {
  •                 /* Clear StandBy flag */
  •                 PWR_ClearFlag(PWR_FLAG_SB);

  •                 /* Check if the StandBy flag is cleared */
  •                 if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
  •                 {
  •                         while(1);
  •                 }

  •                 RTC_WaitForSynchro();

  •                 /* No need to configure the RTC as the RTC config(clock source, enable,
  •                 prescaler,...) are kept after wake-up from STANDBY */
  •         }
  •         /* Select the RTC Clock Source */
  •         RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

  •         SynchPrediv = 0x18F;
  •         AsynchPrediv = 0x63;

  •         #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
  •         /* Enable the LSE OSC */
  •         RCC_LSEConfig(RCC_LSE_ON);

  •         /* Wait till LSE is ready */
  •         while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  •         {
  •         }

  •         /* Select the RTC Clock Source */
  •         RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  •         SynchPrediv = 0xFF;
  •         AsynchPrediv = 0x7F;

  •         #else
  •         #error Please select the RTC Clock source inside the main.c file
  •         #endif /* RTC_CLOCK_SOURCE_LSI */

  •         /* Enable the RTC Clock */
  •         RCC_RTCCLKCmd(ENABLE);

  •         /* Wait for RTC APB registers synchronisation */
  •         RTC_WaitForSynchro();

  • }


回帖(1)

张婷婷

2024-3-27 11:30:10
RTC启动后,只要备份域不复位,那么时钟一直供给RTC,计时是由硬件完成,与中断无关。所以频繁中断不会影响计时。 关键是你的时钟源,时钟源精度影响计数器精度。 如果选择了LSI这个低精度时钟,偏差大是很正常的。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分