不知道是不是配置不对 请大神帮忙看看 用的是stm32l151c8t6 就是进不去中断 到了制定的闹钟时间 没有进中断 求帮忙瞄一瞄是什么地方没配置好 void RTC_conig(void) { static NVIC_InitTypeDef NVIC_InitStructure; static EXTI_InitTypeDef EXTI_InitStructure; static RTC_InitTypeDef RTC_InitStructure; static RTC_TimeTypeDef RTC_TimeStructure; static RTC_DateTypeDef RTC_DateStruct; static RTC_AlarmTypeDef RTC_AlarmStruct; static uint32_t AsynchPrediv = 0, SynchPrediv = 0; uint8_t ret; RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /*!< Allow access to RTC */ PWR_RTCAccessCmd(ENABLE); /*!< 使能外部低速时钟 */ RCC_LSEConfig(RCC_LSE_ON); /*!< 等待外部低速时钟就绪 */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /*!< 配置RTC时钟来源 */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /*!< 使能RTC时钟 */ RCC_RTCCLKCmd(ENABLE); /*!< Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); //配置日历 /* 配置RTC数据寄存器以及时钟分频 */ SynchPrediv = 255; AsynchPrediv = 127;//分频为1Hz RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;//24小时制 /* 检查RTC初始化 */ if (RTC_Init(&RTC_InitStructure) == ERROR) { printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r"); } // while(!ret) // { // ret = RTC_EnterInitMode(); // } RTC_TimeStructure.RTC_H12 = RTC_HourFormat_24;//RTC_H12_PM; RTC_TimeStructure.RTC_Hours = 9; RTC_TimeStructure.RTC_Minutes = 59; RTC_TimeStructure.RTC_Seconds = 1; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); RTC_DateStruct.RTC_Date=4; RTC_DateStruct.RTC_Month=6; RTC_DateStruct.RTC_WeekDay=1; RTC_DateStruct.RTC_Year=18; RTC_SetDate( RTC_Format_BIN, &RTC_DateStruct ); //配置自动定时功能 /* 中断配置 *******************************************************/ 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); /*使能 RTC Wakeup Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //先关闭 RTC_AlarmCmd(RTC_Alarm_A,DISABLE); 才能使用RTC_SetAlarm ret = RTC_AlarmCmd(RTC_Alarm_A,DISABLE); printf("ret = %d\r\n",ret); RTC_AlarmStruct.RTC_AlarmTime.RTC_H12=RTC_HourFormat_24; RTC_AlarmStruct.RTC_AlarmTime.RTC_Hours=9; RTC_AlarmStruct.RTC_AlarmTime.RTC_Minutes=59; RTC_AlarmStruct.RTC_AlarmTime.RTC_Seconds=20; // RTC_AlarmStruct.RTC_AlarmDateWeekDay= // RTC_AlarmStruct.RTC_AlarmDateWeekDaySel= RTC_AlarmStruct.RTC_AlarmMask=RTC_AlarmMask_Seconds | RTC_AlarmMask_Minutes | RTC_AlarmMask_Hours; RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&RTC_AlarmStruct); RTC_ClearFlag(RTC_FLAG_ALRAF); ret = RTC_AlarmCmd(RTC_Alarm_A,ENABLE); printf("ret2 = %d\r\n",ret); /* RTC 唤醒中端配置: Clock Source: RTCDiv_16, Wakeup Time Base: 4s */ // RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16); // RTC_SetWakeUpCounter(0x1FFF);//0x1FFF = 8191; 4s = (8191+1)*(1/(32768/16)) /* 使能 the Wakeup Interrupt */ // RTC_ITConfig(RTC_IT_ALRA, ENABLE); RTC_ITConfig(RTC_IT_ALRA, ENABLE); } ==================中断处理函数======================== void RTC_Alarm_IRQHandler( void ) { if( RTC_GetITStatus( RTC_IT_ALRA ) != RESET ) { RtcRecoverMcuStatus( ); printf("====RTC_Alarm_IRQHandler======\r\n"); TimerIrqHandler( ); RTC_ClearITPendingBit( RTC_IT_ALRA ); EXTI_ClearITPendingBit( EXTI_Line17 ); } } |
这里是要屏蔽的事件,比如需要时分秒,就把日期屏蔽掉。
/* Set the alarm A Masks */
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_Seconds | RTC_AlarmMask_DateWeekDay;
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_WeekDay;
评分
查看全部评分
你的意思是 RTC_AlarmStructure.RTC_AlarmMask 这个是要把对应的标志,比如说我标记了秒,分,时。这些位对应的时间是关闭的?
好的 我理解了 是我自己 理解错手册的意思了 谢谢
是的,这里用的是mask,很多地方都会用到mask,意思都是查不到的。
大神 那句 “意思是查不到的" 这句不太理解
不好意思啊,拼音的问题。应该是差不多
6666