问答

汇集网友智慧,解决技术难题

21ic问答首页 - RTC闹钟的中断

RTC tc

RTC闹钟的中断

yinxiangh2020-09-09
有关RTC闹钟的中断,就是要求每一个小时整点产生一次RTC闹钟中断,前几个小时正常,可后面就不产生RTC中断,各位指点下.
回答 +关注 16
1103人浏览 8人回答问题 分享 举报
8 个回答

  • 唉,还是没有什么结果,算了,多谢大家啦
  • 程序跑飞了 有可能是数据类型的问题
  • 估计是程序哪里跑丢了
  • 应该还是中断配置没对
  • 给你看下,void NVIC_Configuration(void)
    {
            NVIC_InitTypeDef NVIC_InitStructure;
            EXTI_InitTypeDef EXTI_InitStructure;

            /* Set the Vector Table base location at 0x08000000 */
            NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

            /* 2 bit for pre-emption priority, 2 bits for subpriority */
            NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
            //------RTC闹钟-------------------------------------------------------
            NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            
            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);
            
            // 键盘
            NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
           //蓝牙
            NVIC_InitStructure.NVIC_IRQChannel = BLE_INT_EXTI_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            //恢复出厂按键
            NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

    #if WATCHDOG_ENABLE
            NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
    #endif
            
            //------TIM6-------------------------------------------------------
            NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

            #if LOCK_WITH_FINGERPRINT
            // 指纹
            NVIC_InitStructure.NVIC_IRQChannel = FP_MODULE_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
           #endif

            //------TIM4读卡-------------------------------------------------------
            NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            
            //------TIM3-------------------------------------------------------
            NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 8;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

            // console串口
            NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 9;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

            NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 10;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            
            NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 11;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);

            NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 12;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);void RTC_Alarm_IRQHandler(void)
    {        
            keylock_t * keylock=Keylock_Msg_Accept();

            RFID_ChkCard_Disable();               
            if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
            {
                    RTC_ClearITPendingBit(RTC_IT_ALRA);
                    EXTI_ClearITPendingBit(EXTI_Line17);               
                    //System_Sleep_Disable();
                    IntWakeupSce.Sys_sync_flag= SYNC_RECYCLE;
                    }
            if (RTC_GetITStatus(RTC_IT_ALRB) != RESET)
            {                        
                    RTC_ClearITPendingBit(RTC_IT_ALRB);
                    EXTI_ClearITPendingBit(EXTI_Line17);
                    if (keylock->lockedflag == TRUE)
                    {
                            IntWakeupSce.lockedrelease = TRUE;
                            }
                    }
            #ifdef CHECK_WAKEUP_MODE
                    wakeup_mode |= WAKEUP_BY_RTC;
            #endif

    void RTC_RandomPwUpdate_Alarm(void)
    {
            RTC_TimeTypeDef  RTC_TimeStruct;
            RTC_AlarmTypeDef RTC_AlarmStruct;

            APP_TRACE_DBG("%s %d\n", __FUNCTION__, __LINE__);
               RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
            RTCTime_AddCalculate(1, CALCULATE_HOUR, &RTC_TimeStruct);

            /* Allow access to BKP Domain */
            PWR_RTCAccessCmd(ENABLE);
            RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
              RTC_AlarmStruct.RTC_AlarmTime.RTC_H12 = RTC_TimeStruct.RTC_H12;
              RTC_AlarmStruct.RTC_AlarmTime.RTC_Hours = RTC_TimeStruct.RTC_Hours;
        RTC_AlarmStruct.RTC_AlarmTime.RTC_Minutes = (RTC_TimeStruct.RTC_Minutes + 10) % 60;
        RTC_AlarmStruct.RTC_AlarmTime.RTC_Seconds = 0;
            RTC_AlarmStruct.RTC_AlarmDateWeekDay = 0x31;
              RTC_AlarmStruct.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
              RTC_AlarmStruct.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay| RTC_AlarmMask_Hours;
              RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStruct);
              RTC_WaitForSynchro();
            RTC_ClearFlag(RTC_FLAG_ALRAF);        
            EXTI_ClearITPendingBit(EXTI_Line17);
            RTC_ITConfig(RTC_IT_ALRA, ENABLE);
              RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

    我这里改成10分钟一次.
    本来我要的是1个小时一次中断
  • 楼上好建议,毕竟中断次数太少,每次中断处理结束后再执行一次初始化还是可以的。防止配置失效。
  • 你这样每次中断后,你重新初始化一次这个配置。
  • 肯定是处理中断处理的不对了。

您需要登录后才可以回复 登录 | 注册