STM32的RTC无法进入中断 10
问题描述:配置RTC的Alarm或者秒中断,都不能进入中断函数。不知道哪里配置错了。以下是部分代码:voidHAL_RTC_MspInit(RTC_HandleTypeD...
问题描述: 配置RTC的Alarm或者秒中断,都不能进入中断函数。不知道哪里配置错了。以下是部分代码:
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
__HAL_RCC_BACKUPRESET_RELEASE().
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_BKP_CLK_ENABLE();
__HAL_RCC_RTC_ENABLE();
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0x01, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
HAL_NVIC_SetPriority(RTC_IRQn, 0x00, 0);
HAL_NVIC_EnableIRQ(RTC_IRQn);
}
void RTC_IRQHandler(void)
{
HAL_RTCEx_RTCIRQHandler(&rtcHandler);
}
void RTC_Alarm_IRQHandler(void)
{
HAL_RTC_AlarmIRQHandler(&rtcHandler);
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
blinkLed(10, 100);
rtc_alarm_flag++;
}
void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc)
{
blinkLed(10, 100);
rtc_alarm_flag++;
}
void MX_RTC_Init()
{
rtcHandler.Instance = RTC;
rtcHandler.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
rtcHandler.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
HAL_RTC_Init(&rtcHandler);
if (HAL_RTCEx_BKUPRead(&rtcHandler, RTC_BKP_DR1) != CFG_MAGIC_NUMBER)
{
HAL_RTC_SetDate(&rtcHandler, &sDate, RTC_FORMAT_BCD);
HAL_RTC_SetTime(&rtcHandler, &sTime, RTC_FORMAT_BCD);
HAL_RTCEx_BKUPWrite(&rtcHandler, RTC_BKP_DR1, CFG_MAGIC_NUMBER);
}
HAL_RTC_SetAlarm_IT(&rtcHandler, &sAlarm, RTC_FORMAT_BCD);
HAL_RTCEx_SetSecond_IT(&rtcHandler);
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 展开
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
__HAL_RCC_BACKUPRESET_RELEASE().
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_BKP_CLK_ENABLE();
__HAL_RCC_RTC_ENABLE();
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0x01, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
HAL_NVIC_SetPriority(RTC_IRQn, 0x00, 0);
HAL_NVIC_EnableIRQ(RTC_IRQn);
}
void RTC_IRQHandler(void)
{
HAL_RTCEx_RTCIRQHandler(&rtcHandler);
}
void RTC_Alarm_IRQHandler(void)
{
HAL_RTC_AlarmIRQHandler(&rtcHandler);
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
blinkLed(10, 100);
rtc_alarm_flag++;
}
void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc)
{
blinkLed(10, 100);
rtc_alarm_flag++;
}
void MX_RTC_Init()
{
rtcHandler.Instance = RTC;
rtcHandler.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
rtcHandler.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
HAL_RTC_Init(&rtcHandler);
if (HAL_RTCEx_BKUPRead(&rtcHandler, RTC_BKP_DR1) != CFG_MAGIC_NUMBER)
{
HAL_RTC_SetDate(&rtcHandler, &sDate, RTC_FORMAT_BCD);
HAL_RTC_SetTime(&rtcHandler, &sTime, RTC_FORMAT_BCD);
HAL_RTCEx_BKUPWrite(&rtcHandler, RTC_BKP_DR1, CFG_MAGIC_NUMBER);
}
HAL_RTC_SetAlarm_IT(&rtcHandler, &sAlarm, RTC_FORMAT_BCD);
HAL_RTCEx_SetSecond_IT(&rtcHandler);
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询