OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 7639|回复: 6

STM32F030C8T6,想弄一个RTC定时唤醒STOP的例程

[复制链接]

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
发表于 2018-1-18 21:47:36 | 显示全部楼层 |阅读模式
5金钱
STM32F030C8T6,想弄一个RTC定时唤醒STOP的例程,不知道怎么弄,以下是RCC的程序
void RTC_Config(void)
{
  RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_InitTypeDef   RTC_InitStructure;

  /* RTC Configuration **********************************************************/
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);

  /* Reset back up registers */
  RCC_BackupResetCmd(ENABLE);
  RCC_BackupResetCmd(DISABLE);

  /* Enable the LSE */
  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);

  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();  

  /* Set RTC calendar clock to 1 HZ (1 second) */
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F-1;
  RTC_InitStructure.RTC_SynchPrediv = 0x1fff-1;

  if (RTC_Init(&RTC_InitStructure) == ERROR)
  {
    while(1);
  }

  /* Set the time to 01h 00mn 00s AM */
  RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
  RTC_TimeStructure.RTC_Hours   = 0x01;
  RTC_TimeStructure.RTC_Minutes = 0x00;
  RTC_TimeStructure.RTC_Seconds = 0x00;  

  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
}

void RTC_AlarmConfig(void)
{
  RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_AlarmTypeDef  RTC_AlarmStructure;
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);//清除外部中断,RTC中断函数里面每次都要清除
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable the RTC Alarm Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;         
   NVIC_InitStructure.NVIC_IRQChannelPriority=0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

       
        RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
        RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
         RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_8);

        /* Get current time */
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);


  /* Enable the RTC Alarm A interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);

  /* Enable the alarm */
  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

  /* Clear the Alarm A Pending Bit */
  RTC_ClearITPendingBit(RTC_IT_ALRA);  

}

以下问问饿你中断函数
void  RTC_IRQHandler(void)
{
  if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
  {
           /* Clear the Alarm A Pending Bit */
         RTC_ClearITPendingBit(RTC_IT_ALRA);       
               
          
                 temp1++;

   }  
              EXTI_ClearITPendingBit(EXTI_Line17);   

}

最佳答案

查看完整内容[请看2#楼]

自己顶一个,这个问题已经解决,就是RTC定时不太准确,能进入STOP模式,中断也可唤醒
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
 楼主| 发表于 2018-1-18 21:47:37 | 显示全部楼层
自己顶一个,这个问题已经解决,就是RTC定时不太准确,能进入STOP模式,中断也可唤醒
回复

使用道具 举报

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
 楼主| 发表于 2018-1-18 21:47:37 | 显示全部楼层
按照程序, temp1应该是32秒左右自加一个数,但实际上是1秒加一个数,不知道哪里出问题了,有人说RTC定时唤醒STOP模式需要RTCAlarm_IRQHandler() 中断,但是STM32F030C8T6没有这个中断函数,怎么办?
回复

使用道具 举报

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
 楼主| 发表于 2018-1-18 21:50:25 | 显示全部楼层
i nt main(void)       {                RCC1_Configuration();                        RTC_Config();         RTC_AlarmConfig();           while(1)                         {                                RTC_AlarmConfig();                                                     PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);                          RTC_ITConfig(RTC_IT_ALRA, DISABLE);                          RTC_AlarmCmd(RTC_Alarm_A, DISABLE);                                                                                                   }               }
回复

使用道具 举报

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
 楼主| 发表于 2018-1-18 21:51:16 | 显示全部楼层
lumilu 发表于 2018-1-18 21:50
i nt main(void)       {                RCC1_Configuration();                        RTC_Config();         R ...

这是main函数,也进不了STOP模式
回复

使用道具 举报

24

主题

157

帖子

0

精华

高级会员

Rank: 4

积分
523
金钱
523
注册时间
2016-1-7
在线时间
131 小时
 楼主| 发表于 2018-1-18 21:52:41 | 显示全部楼层
该程序无法进入STOP模式,
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2018-1-19 01:27:55 | 显示全部楼层
帮顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-11 23:10

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表