Skip to main content
Vinay1
Associate III
November 17, 2021
Solved

how to set RTC alarm for all day in stm32f407vgt?

  • November 17, 2021
  • 3 replies
  • 1896 views

mcu: " STM32F407VGT Discovery Board - DICS1 "

application: RTC ALARM

i am trying to set the RTC alarm for every 15 minutes in all the day. in each RTCAlarmcallback function i am setting the RTC alarm again with sTime.Minutes + 15.

if sTime.Minutes is greter than 45, i am setting RTC alarm minutes [i.e, sRtcAlarmTime->Minutes] to 0

is i am doing correct?

pls guide me to do this.

this bellow function which is i am using:

void set_Alarm_A (RTC_TimeTypeDef *sRtcAlarmTime, RTC_DateTypeDef *sRtcAlarmDate)

{

RTC_AlarmTypeDef sAlarm = {0};

/*

* Set the Alarm A  

*/

  sAlarm.AlarmTime.Hours = sRtcAlarmTime->Hours;

  sAlarm.AlarmTime.Minutes = sRtcAlarmTime->Minutes;

  sAlarm.AlarmTime.Seconds = sRtcAlarmTime->Seconds;

  sAlarm.AlarmTime.SubSeconds = sRtcAlarmTime->SubSeconds;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_SECONDS;

  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;

  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

  sAlarm.AlarmDateWeekDay = sRtcAlarmDate->Date;

  sAlarm.Alarm = RTC_ALARM_A;

  if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)

  {

   Error_Handler();

  }

}

is this correct?

This topic has been closed for replies.
Best answer by waclawek.jan

I don't use Cube, but that probably directly converts to RTC_ALRMxR.MSKx bits, see RTC chapter in RM.

In other words, in the above setting, date, hours and seconds are ignored for checking the alarm, i.e. only minutes are checked.

JW

3 replies

waclawek.jan
Super User
November 17, 2021

> if sTime.Minutes is greter than 45, i am setting RTC alarm minutes [i.e, sRtcAlarmTime->Minutes] to 0

And if it's equal to 45?

JW

Vinay1
Vinay1Author
Associate III
November 18, 2021

if its equals to 45 min i will set RTC Alarm Minutes to 0

waclawek.jan
waclawek.janBest answer
Super User
November 18, 2021

I don't use Cube, but that probably directly converts to RTC_ALRMxR.MSKx bits, see RTC chapter in RM.

In other words, in the above setting, date, hours and seconds are ignored for checking the alarm, i.e. only minutes are checked.

JW

Vinay1
Vinay1Author
Associate III
November 18, 2021

thank you

Tesla DeLorean
Guru
November 18, 2021

Assume you need to advance hours when you overflow minutes.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..