请选择 进入手机版 | 继续访问电脑版

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

使用STM32F072 RTC模块每隔1分钟触发一次中断

[复制链接]
冷不丁-357544 提问时间:2020-8-18 18:25 /
使用STM32F072 RTC模块中断,这样设置完成后,每一分钟进一次,时钟配置的是外部LSE 32.768kHz,救助大家这个时间是从哪里设置的
void RTC_AlarmConfig(void)
{
        RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_AlarmTypeDef  RTC_AlarmStructure;
  EXTI_InitTypeDef  EXTI_InitStructure;
  NVIC_InitTypeDef  NVIC_InitStructure;
        RTC_DateTimeTypeDef RTC_DateTimeStructure;

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        PWR_BackupAccessCmd(ENABLE);   

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

  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);  

   /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);
  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 = 2;//RTC_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPriority=1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
void  RTC_IRQHandler(void)
{
  RTC_TimeTypeDef   RTC_TimeStructure;
  RTC_AlarmTypeDef  RTC_AlarmStructure;
  RTC_DateTimeTypeDef RTC_DateTimeStructure;

        USART1_Printf_RTC();                         //RTC

if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
                 RTC_ClearITPendingBit(RTC_IT_ALRA);
                 
                 RTC_GetDateTime(&RTC_DateTimeStructure);

                RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);  
                 
                        RTC_ITConfig(RTC_IT_ALRA, ENABLE);  
                /* Enable the alarm */
                RTC_AlarmCmd(RTC_Alarm_A, ENABLE);      
}  

EXTI_ClearITPendingBit(EXTI_Line17);   

}

收藏 评论3 发布时间:2020-8-18 18:25

举报

3个回答
Tcreat 回答时间:2020-8-19 08:42:52
Tcreat 回答时间:2020-8-19 08:46:54
冷不丁-357544 回答时间:2020-8-19 11:31:59
Tcreat 发表于 2020-8-19 08:42
这里有你要的例程 :https://www.stmcu.org.cn/document/detail/index/id-213581

之前按例程中的方法配置的就不进中断了,没找出来原因
void RTC_AlarmConfig(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
  RTC_AlarmTypeDef RTC_AlarmStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  RTC_AlarmStructInit(&RTC_AlarmStructure);
   
  /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);
  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 = 2;//RTC_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Set the alarmA Masks */
  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
  RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
  
  /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
  RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_8);

  /* Enable AlarmA interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);
}



void RTC_IRQHandler(void)
{
        USART1_Printf_RTC();                         //RTC
       
  /* Check on the AlarmA flag and on the number of interrupts per Second (60*8) */
  if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
  {
    /* ALARM is enabled */
//    ALARM_Occured = 1;
   
    /* Clear RTC AlarmA Flags */
    RTC_ClearITPendingBit(RTC_IT_ALRA);
  }
  /* Clear the EXTIL line 17 */
  EXTI_ClearITPendingBit(EXTI_Line17);
}
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版