STM32F030 的RTC 定时3秒,进入中断后,清除所有标志位,再重设定时时间3秒,后开闹钟,竟然不能再进中断?这个是为什么
if(RTC_Ge
tiTStatus(RTC_IT_ALRA)!=0)//RTC_IT_ALRA
{
}
RCC_LSICmd(DISABLE);//OPEN LSI
RTC_Al
ARMCmd(RTC_Alarm_A,DISABLE);//ÄÖÖÓʹÄÜ
RTC_ITConfig(RTC_IT_ALRA, DISABLE);//ÖжÏÅäÖÃ
RTC_ClearFlag(RTC_FLAG_ALRAF);//alarm flag
RTC_ClearFlag(RTC_FLAG_WUTF);//WakeUp Timer flag
RTC_ClearFlag(RTC_FLAG_TAMP2F);
RTC_ClearFlag(RTC_FLAG_TAMP1F);
RTC_ClearFlag(RTC_FLAG_TSOVF);
RTC_ClearFlag(RTC_FLAG_TSF);
RTC_ClearFlag(RTC_FLAG_RSF);
RTC_ClearITPendingBit(RTC_IT_TS);
RTC_ClearITPendingBit(RTC_IT_WUT);
RTC_ClearITPendingBit(RTC_IT_ALRA);
RTC_ClearITPendingBit(RTC_IT_TAMP1);
RTC_ClearITPendingBit(RTC_IT_TAMP2);
sleeptemp1=11;
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);//DOGдʹÄÜ 0X5555
IWDG_SetPrescaler(0X7);//Ô¤·ÖƵ
IWDG_SetReload(0XAAAA);//×°ÔØÖµ
IWDG_ReloadCounter();//0XAAAA
IWDG_Enable();//¿ªÆôDOG
EXTI_ClearITPendingBit(EXTI_Line0 | EXTI_Line2 | EXTI_Line4 | EXTI_Line1 | EXTI_Line17); // ?? EXIT ????
RTC_AlarmCmd(RTC_Alarm_A,DISABLE);//RTC-CR-ALARM ¹ØµôÄÖÖÓ
RTC_TIMESET.RTC_H12 = RTC_H12_AM;
RTC_TIMESET.RTC_Hours = 0x02;
RTC_TIMESET.RTC_Minutes = 0x00;
RTC_TIMESET.RTC_Seconds = 0x02;
RTC_SetTime(RTC_Format_BIN, &RTC_TIMESET);
RTC_SLEEP();
sleeptemp1=1;
RTC_ITConfig(RTC_IT_ALRA, ENABLE);//ÖжÏÅäÖÃ
}
void RTC_CONFIG(void)
{
RTC_InitTypeDef RTC_InitStruct;
RTC_TimeTypeDef RTC_TIMESET;
int LSIFreq=40000;
RTC_INT();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);//open the clock
PWR_BackupAccessCmd(ENABLE);//POWER OPEN
PWR_ClearFlag(PWR_FLAG_WU);
RCC_LSICmd(ENABLE);//OPEN LSI
/* 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);
}
IWDG_ReloadCounter();//FEED WACHDOG
RTC_WaitForSynchro();
/* No need to configure the RTC as the RTC config(clock source, enable,
prescaler,...) are kept after wake-up from STANDBY */
}
else
{
/* RTC Configuration ******************************************************/
/* Reset Backup Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//4000
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
IWDG_ReloadCounter();//FEED WACHDOG
/* Get the LSI frequency: TIM14 is used to measure the LSI frequency */
//LSIFreq = GetLSIFrequency();
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStruct.RTC_AsynchPrediv = 127;
// RTC_InitStruct.RTC_SynchPrediv = (LSIFreq/100) - 1;
RTC_InitStruct.RTC_SynchPrediv = 255;
RTC_Init(&RTC_InitStruct);
/* Set the time to 01h 00mn 00s AM */
RTC_TIMESET.RTC_H12 = RTC_H12_AM;
RTC_TIMESET.RTC_Hours = 0x02;
RTC_TIMESET.RTC_Minutes = 0x00;
RTC_TIMESET.RTC_Seconds = 0x00;
IWDG_ReloadCounter();//FEED WACHDOG
RTC_SetTime(RTC_Format_BIN, &RTC_TIMESET);
}
// RTC_DeInit();//³õʼ»¯RTC¸÷¼Ä´æÆ÷Ϊ³õÖµ
//
// RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//4000 RCC_RTCCLKSource_LSI LSI_VALUE RCC_RTCCLKSource_LSI
// RCC_RTCCLKCmd(ENABLE);//ENABLE rtc CLOCK
}
void RTC_INT(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;IWDG_ReloadCounter();//FEED WACHDOG
/* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
EXTI_ClearITPendingBit(EXTI_Line17);//¡¢¡¢RTC_IRQn
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//EXTI_Mode_Event EXTI_Mode_Interrupt
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
IWDG_ReloadCounter();//FEED WACHDOG
/* Enable the RTC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;//TIM17_IRQn
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;//NVIC_IRQChannelPriority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//EXTI_ClearITPendingBit(EXTI_Line0 | EXTI_Line2 | EXTI_Line4 | EXTI_Line1 | EXTI_Line17); // ?? EXIT ????
IWDG_ReloadCounter();//FEED WACHDOG
}
void RTC_SLEEP(void)
{
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_TimeTypeDef RTC_TIMESET;
RTC_AlarmCmd(RTC_Alarm_A,DISABLE);//RTC-CR-ALARM ¹ØµôÄÖÖÓ
IWDG_ReloadCounter();//FEED WACHDOG
RTC_GetTime(RTC_Format_BIN, &RTC_TIMESET);
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM;//0
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours=0x02;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes=0x00;
// RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=( RTC_TIMESET.RTC_Seconds + 0x3b )%60;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=0x02; //¶¨Ê±Ê±¼äÃë
IWDG_ReloadCounter();//FEED WACHDOG
RTC_AlarmStructure.RTC_AlarmDateWeekDay = 31;
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes;
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
/* Clear RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
RTC_ClearFlag(RTC_FLAG_ALRAF);//alarm flag
RTC_ClearFlag(RTC_FLAG_WUTF);//WakeUp Timer flag
RTC_ClearITPendingBit(RTC_IT_TS);
RTC_ClearITPendingBit(RTC_IT_ALRA);
RTC_ClearITPendingBit(RTC_IT_TAMP1);
RTC_ClearITPendingBit(RTC_IT_TAMP2);
/* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from
STANDBY mode (RTC Alarm IT not enabled in NVIC) */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the Alarm A */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
IWDG_ReloadCounter();//FEED WACHDOG
/* Clear RTC Alarm Flag */
// RTC_ClearFlag(RTC_FLAG_ALRAF);
// EXTI_ClearITPendingBit(EXTI_Line0 | EXTI_Line2 | EXTI_Line4 | EXTI_Line1 | EXTI_Line17); // ?? EXIT ????
// PWR_EnterSTANDBYMode();
// PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI);//WFI=every interrput PWR_Regulator_LowPower PWR_Regulator_ON
}
ALARM后,我把启动时的代码又重跑了一次,应当是初始化了吧,第一次是能进入中断的,但是进入一次后,再也不进了
一周热门 更多>