各位,小弟刚接触Cortex-M0核单片机,用的是STM32F042.在使用RTC Alarm功能时,遇到问题,先贴源码
//初始化
void RTC_init(void)
{
RTC_InitTypeDef RTC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//Enable the LSI OSC
RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
//40k
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
//时基配置-1s
RTC_InitStructure.RTC_AsynchPrediv = 0x63;
RTC_InitStructure.RTC_SynchPrediv = 0x18F;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
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);
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//校准时钟为: 00:01:00
void RTC_TimeRegulate(void)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x00;
RTC_TimeStructure.RTC_Minutes = 0x01;
RTC_TimeStructure.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
}
//闹钟设置
void RTC_TimeAlarm(u8 tInterval)
{
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = tInterval;
//屏蔽天数、小时和秒
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay|RTC_AlarmMask_Hours|RTC_AlarmMask_Seconds;
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
//中断
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
int main(void)
{
RTC_init();
RTC_TimeRegulate();
//1min中断一次
RTC_TimeAlarm(0x01);
while(1);
}
void RTC_IRQHandler(void)
{
RTC_ClearITPendingBit(RTC_IT_ALRA);
EXTI_ClearITPendingBit(EXTI_Line17);
//...
}
实现的功能是:1min进一次RTC中断处理业务。但是运行的结果是进不了中断!
请各位帮忙看看问题出在哪里?谢谢
|