哪位大神帮我看看我的程序,我用M4 的RTC配置闹钟,然后配置好了,不知道为什么就是闹钟时间到了就是没有执行闹钟中断函数。。。。。。谢谢
闹钟设置函数
void RTC_Set_ALRMAR_Time(u8 date,u8 hour, u8 min, u8 sec)
{
u32 temp = 0;
RCC->APB2ENR |= 1 << 14;
RCC->APB1ENR |= 1 << 28;
PWR->CR |= 1 << 8;
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->CR &=~(1<<8);
while( (RTC->ISR & (1 <<0))==0)
{
}
RTC->CR &=~(1<<12);
// RTC->ALRMAR =0 ;
RTC->ALRMAR &=~(1<<7);
RTC->ALRMAR &=~(1<<22);
RTC->ALRMAR |= 1<<15;
RTC->ALRMAR |= 1<<23;
RTC->ALRMAR &=~(1<<30);
RTC->ALRMAR |= 1<<31;
temp = ((u32)(RTC_DECtoBCD(sec) & 0x7f )<< 0);
RTC->ALRMAR |= temp;
temp = ((u32)(RTC_DECtoBCD(min) &0x7f) << 8);
RTC->ALRMAR |= temp;
temp = ((u32)(RTC_DECtoBCD(hour) & 0x3f)<< 16);
RTC->ALRMAR |= temp;
temp = ((u32)(RTC_DECtoBCD(date)&0x3f) << 24);
RTC->ALRMAR |= temp;
// EXTI->PR |=1<<17;
// RTC->ISR &=~(1<<8);
//ÖD¶Ïê1Äü
EXTI->IMR |=1<<17;
EXTI->RTSR |=1<<17;
NVIC_SetPriorityGrouping(5);
NVIC_SetPriority(RTC_Alarm_IRQn ,NVIC_EncodePriority(5,1,3));
NVIC_EnableIRQ(RTC_Alarm_IRQn);
// RTC->ALRMASSR=0;
RTC->CR |=1<<21;
RTC->CR |=1<<12;
// RTC->CR &=~(1<<20);
RTC->CR |= 1<<8;
RTC->WPR = 0xff;
}
中断函数
void RTC_Alarm_IRQHandler(void)
{
if(EXTI->PR & 1 << 17)
{
EXTI->PR |= (1 << 17);
if(RTC->ISR & 1 << 8)
{
RTC->ISR &= ~(1 << 8);
GPIOF->ODR &=~(1<<6);
}
}
}
一周热门 更多>