I am using STM32l151vbt6 MCU and I am trying to configure RTC Alarm for every 15th minute. (That is 0, 15, 30 and 45th minute of the every hour.)
I can configure the alarm and it will work for the first time, if I try to set it again after the alarm occurs, it would set to previous alarm state. If I reset the MCU I can set the alarm and it will wake the controller from the stop mode when the alarm occurs. Please let me know how can I set the next alarm without resetting the MCU.
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* 8(hour) and 19(day) are masked and there is no effect on the alarm */
RTC_AlarmTypeDef RTC_AlarmStructure =
{
0,
0,
0,
RTC_H12_AM,
(RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Hours),
RTC_AlarmDateWeekDaySel_Date,
19
};
const uint8_t alarm_interval[4] = { 15, 30, 45, 0 };
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = alarm_interval[RTC_current_time.minute/15];
/*Alarm A will be configured*/
RTC_Alarm_Config(&RTC_AlarmStructure);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void RTC_Alarm_Config(RTC_AlarmTypeDef *RTC_AlarmStructure)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
RTC_AlarmCmd(RTC_Alarm_B, DISABLE);//Not using this
/* EXTI configuration */
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);
/* Enable the RTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, RTC_AlarmStructure);
/* Clear RTC AlarmA Flags */
RTC_ClearITPendingBit(RTC_IT_ALRA);
/* Enable AlarmA interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
Best Answer
We faced the same problem while working with RTC on my STM32F030 Controller. Our alarm interrupt triggered once, but it would never trigger again.
The problem was as follows:
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
Reference manual RM0360 for STM32F030 and STM32F070 states that:
We solved the problem by making following changes to the IRQ handler of RTC: