I'm trying to generate an interrupt every 60 seconds using alarm A. I put a HAL_GPIO_Toggle instruction inside the interrupt HAL_RTC_AlarmAEventCallback to turn an LED on to see if it triggers but I get nothing. I'm not routing the alarm to the output pins. This board has lots of goodies. I'm using the base project that sets up all the stuff in the board. I disabled FREERTOS, SDMMC1 and FATFS.
I checked the registers for alarm enable (ALRAE bit in RTC_CR register) and interrupt enable (ALRAIE bit in RTC_CR register) and they're both set. I set the current time to 12:31:32 (HH:MM:SS) and the date to Tuesday June 27, 2023. I have alarm A "Alarm Mask Seconds" enable and the seconds set to 0. I'm thinking when the seconds match, an interrupt should happen? but the alarm flag never gets set (ALRAF in RTC_ISR register). I was thinking I need to disable the interrupt after it happens so that it doesn't trigger for a whole second but I'm not sure how that works ... I haven't gotten there yet.
Why doesn't the interrupt trigger?
Thanks
Here is the code for the RTC init:
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/* Initialize RTC Only */
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date */
sTime.Hours = 0x12;
sTime.Minutes = 0x31;
sTime.Seconds = 0x32;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_TUESDAY;
sDate.Month = RTC_MONTH_JUNE;
sDate.Date = 0x27;
sDate.Year = 0x23;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/** Enable the Alarm A */
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x0;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; //RTC_DAYLIGHTSAVING_NONE=0
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; //RTC_STOREOPERATION_RESET=0
sAlarm.AlarmMask = RTC_ALARMMASK_SECONDS; //RTC_ALARMMASK_SECONDS=(0x1UL << (7U))
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; //RTC_ALARMSUBSECONDMASK_ALL=0
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;//RTC_ALARMDATEWEEKDAYSEL_DATE=0
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}