求助各位坛友,最近在实现一个RTC闹钟中断,每10分钟采集一次相关数据,目前实现的情况有些异常, 闹钟有时候只能循环设定2-3次然后就没有再进入中断了,程序没有跑飞,网上查到说需要每次闹钟结束之后读取当前时间再去设定,我也确实是这么做的,但是总是循环设定几次之后闹钟就没了。用的芯片是STM32L476,在一个HAL库的程序上添加的这个功能。
void set_invernal_alarm(uint32_t min)//按分钟去设置
{
uint8_t day, h, m, s;
RTC_AlarmTypeDef alarmsturcture;
rtc_info_t rtc_alarm_set;
get_rtc(&rtc_alarm_set);
h = (min%1440) / 60;
m = (min%1440) % 60;
if((rtc_alarm_set.Minutes + m) >= 0x60)//计算分钟
{
m = (rtc_alarm_set.Minutes + m) - 0x60;
h += 0x1;
}
else
{ m = (rtc_alarm_set.Minutes + m); }
if((rtc_alarm_set.Hours + h) >= 0x24)//计算小时
{
h = (rtc_alarm_set.Hours + h) - 0x24;
day += 0x1;
}
else
{ h = (rtc_alarm_set.Hours + h); }
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
alarmsturcture.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_SECONDS;//只设定时钟和分钟
alarmsturcture.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
alarmsturcture.Alarm = RTC_ALARM_A;
alarmsturcture.AlarmTime.Hours = h;
alarmsturcture.AlarmTime.Minutes = m;
alarmsturcture.AlarmTime.Seconds = 0x00;
alarmsturcture.AlarmTime.SubSeconds = 0x00;
if( h < 0x12 )
{ alarmsturcture.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; }
else
{ alarmsturcture.AlarmTime.TimeFormat = RTC_HOURFORMAT12_PM; }
HAL_RTC_SetAlarm_IT(&hrtc, &alarmsturcture, RTC_FORMAT_BCD);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>