/* RTC init function */ void MX_RTC_Init(void) { RTC_TimeTypeDef sTime; RTC_DateTypeDef sDate; RTC_AlarmTypeDef sAlarm; /**Initialize RTC and set the Time and Date */ 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; HAL_RTC_Init(&hrtc); sTime.Hours = 0; sTime.Minutes = 0; sTime.Seconds = 0; sTime.SubSeconds = 0; sTime.TimeFormat = RTC_HOURFORMAT12_AM; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.StoreOperation = RTC_STOREOPERATION_RESET; HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BIN); sDate.WeekDay = RTC_WEEKDAY_MONDAY; sDate.Month = RTC_MONTH_JANUARY; sDate.Date = 1; sDate.Year = 0; HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BIN); /**Enable the Alarm A */ sAlarm.AlarmTime.Hours = 0; sAlarm.AlarmTime.Minutes = 0; sAlarm.AlarmTime.Seconds = 0; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_NONE; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 1; sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); /**Enable the Alarm B */ sAlarm.Alarm = RTC_ALARM_B; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); /**Enable the WakeUp */ HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 196, RTC_WAKEUPCLOCK_RTCCLK_DIV2); }
TM_RTC_Result_t TM_RTC_EnableAlarm(TM_RTC_Alarm_t Alarm, TM_RTC_AlarmTime_t* DataTime, TM_RTC_Format_t format) { RTC_AlarmTypeDef salarmstructure; /* Alarm type is every week the same day in a week */ if (DataTime->Type == TM_RTC_AlarmType_DayInWeek) { /* Alarm trigger every week the same day in a week */ salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; /* Week day can be between 1 and 7 */ if (DataTime->Day == 0) { salarmstructure.AlarmDateWeekDay = 1; } else if (DataTime->Day > 7) { salarmstructure.AlarmDateWeekDay = 7; } else { salarmstructure.AlarmDateWeekDay = DataTime->Day; } } else { /* Alarm type is every month the same day */ /* Alarm trigger every month the same day in a month */ salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; /* Month day can be between 1 and 31 */ if (DataTime->Day == 0) { salarmstructure.AlarmDateWeekDay = 1; } else if (DataTime->Day > 31) { salarmstructure.AlarmDateWeekDay = 31; } else { salarmstructure.AlarmDateWeekDay = DataTime->Day; } } /* Set alarm settings */ if (Alarm == TM_RTC_Alarm_A) { salarmstructure.Alarm = RTC_ALARM_A; } else { salarmstructure.Alarm = RTC_ALARM_B; } salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT_24; salarmstructure.AlarmTime.Hours = DataTime->Hours; salarmstructure.AlarmTime.Minutes = DataTime->Minutes; salarmstructure.AlarmTime.Seconds = DataTime->Seconds; salarmstructure.AlarmTime.SubSeconds = 0; /* Enable alarm with interrupt */ if (format == TM_RTC_Format_BIN) { HAL_RTC_SetAlarm_IT(&hRTC, &salarmstructure, RTC_FORMAT_BIN); } else { HAL_RTC_SetAlarm_IT(&hRTC, &salarmstructure, RTC_FORMAT_BCD); } /* Enable NVIC */ HAL_NVIC_SetPriority(RTC_Alarm_IRQn, RTC_NVIC_PRIORITY, RTC_NVIC_ALARM_SUBPRIORITY); HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn); /* Return Ok */ return TM_RTC_Result_Ok; }
static void RtcStartWakeUpAlarm( uint32_t timeoutValue ) { RtcCalendar_t now; RtcCalendar_t alarmTimer; RTC_AlarmTypeDef alarmStructure; HAL_RTC_DeactivateAlarm( &RtcHandle, RTC_ALARM_A ); HAL_RTCEx_DeactivateWakeUpTimer( &RtcHandle ); // Load the RTC calendar now = RtcGetCalendar( ); // Save the calendar into RtcCalendarContext to be able to calculate the elapsed time RtcCalendarContext = now; // timeoutValue is in ms alarmTimer = RtcComputeTimerTimeToAlarmTick( timeoutValue, now ); alarmStructure.Alarm = RTC_ALARM_A; alarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; alarmStructure.AlarmMask = RTC_ALARMMASK_NONE; alarmStructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; alarmStructure.AlarmTime.Seconds = alarmTimer.CalendarTime.Seconds; alarmStructure.AlarmTime.Minutes = alarmTimer.CalendarTime.Minutes; alarmStructure.AlarmTime.Hours = alarmTimer.CalendarTime.Hours; alarmStructure.AlarmDateWeekDay = alarmTimer.CalendarDate.Date; if( HAL_RTC_SetAlarm_IT( &RtcHandle, &alarmStructure, RTC_FORMAT_BIN ) != HAL_OK ) { assert_param( FAIL ); } }
static void rtc_alarm_config(uint32_t time) { RTC_AlarmTypeDef salarmstructure; /*##-3- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 02:20:30 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_TUESDAY; salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; salarmstructure.AlarmTime.Hours = 0x01; salarmstructure.AlarmTime.Minutes = 0x20; salarmstructure.AlarmTime.Seconds = 0x20; salarmstructure.AlarmTime.SubSeconds = 0x02; if(HAL_RTC_SetAlarm_IT(&RTCHandle,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/* RTC init function */ void MX_RTC_Init(void) { // RTC_TimeTypeDef sTime; // RTC_DateTypeDef sDate; RTC_AlarmTypeDef sAlarm; /**Initialize RTC and set the Time and Date */ 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(); } /* Set time and date (for the very first time) */ // sTime.Hours = 1; // sTime.Minutes = 7; // sTime.Seconds = 0; // sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; // sTime.StoreOperation = RTC_STOREOPERATION_RESET; // if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK) // { // Error_Handler(); // } // // sDate.WeekDay = RTC_WEEKDAY_THURSDAY; // sDate.Month = RTC_MONTH_MAY; // sDate.Date = 26; // sDate.Year = 16; // // if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK) // { // Error_Handler(); // } /**Enable the Alarm A */ sAlarm.AlarmTime.Hours = 0; sAlarm.AlarmTime.Minutes = 0; sAlarm.AlarmTime.Seconds = 0; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_ALL; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 1; sAlarm.Alarm = RTC_ALARM_A; if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK) { Error_Handler(); } }
void rtcSetAlarm(void) { RTC_AlarmTypeDef salarmstructure; /* Set Alarm to 02:20:30 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_WEDNESDAY; salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; #ifdef DEBUG salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; /* Alarm every minute */ #else salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; /* Alarm every day */ #endif salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_None; salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; salarmstructure.AlarmTime.Hours = 23; salarmstructure.AlarmTime.Minutes = 59; salarmstructure.AlarmTime.Seconds = 59; salarmstructure.AlarmTime.SubSeconds = 56; if(HAL_RTC_SetAlarm_IT(&RtcHandle,&salarmstructure,FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == KEY_BUTTON_PIN) { HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN); /* Set the alarm to current time + 5s */ RTC_AlarmStructure.Alarm = RTC_ALARM_A; RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat; RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours; RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes; RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 0x05) % 60; RTC_AlarmStructure.AlarmDateWeekDay = 0x31; RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry mainly when using more than one wakeup source this is to not miss any wakeup event: - Disable all used wakeup sources, - Clear all related wakeup flags, - Re-enable all used wakeup sources, - Enter the Standby mode. */ /*## Disable all used wakeup sources #####################################*/ /* Disable Wake-up timer */ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); /* Disable RTC Alarm */ HAL_RTC_DeactivateAlarm(&RTCHandle, RTC_ALARM_A); /*## Clear all related wakeup flags ######################################*/ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Clear the Alarm Flag */ __HAL_RTC_ALARM_CLEAR_FLAG(&RTCHandle, RTC_FLAG_ALRAF); /*## Re-enable all used wakeup sources ###################################*/ /* Set RTC alarm */ if(HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Enable WKUP pin */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /* Turn LED1 off */ BSP_LED_Off(LED1); /*## Enter Standby Mode ##################################################*/ HAL_PWR_EnterSTANDBYMode(); } }
/** * @brief RTC Alarm configuration function using interrupt * @param sel_Alarm Select the Alarm * @arg AlarmA * @arg AlarmB * @arg BothAlarm To set the Alarm A and Alarm B * @param hour Set the Hour for Alarm interrupt * @param minute Set the Minute for Alarm interrupt * @param second Set the Second for Alarm interrupt * @param dayselect Select the alarm type * @arg RTC_ALARMDATEWEEKDAYSEL_DATE Alarm interrupt occur day of every month * @arg RTC_ALARMDATEWEEKDAYSEL_WEEKDAY Alarm interrupt occur day of every week * * NOTE If you want to configure both alarm with different time then * type the whole structure differently for both alarm with Set alarm function. */ void BSP_RTC_Alarm_Init(Alarm_Typedef sel_Alarm, uint8_t hour, uint8_t minute, uint8_t second, uint8_t dayselect) { RTC_AlarmTypeDef sAlarm; sAlarm.AlarmTime.Hours = hour; sAlarm.AlarmTime.Minutes = minute; sAlarm.AlarmTime.Seconds = second; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_NONE; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; if (dayselect == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY) { sAlarm.AlarmDateWeekDaySel = dayselect; sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; } else if (dayselect == RTC_ALARMDATEWEEKDAYSEL_DATE) { sAlarm.AlarmDateWeekDaySel = dayselect; sAlarm.AlarmDateWeekDay = 1; } if(sel_Alarm == AlarmA) { sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc_bsp, &sAlarm, FORMAT_BIN); } else if (sel_Alarm == AlarmB) { sAlarm.Alarm = RTC_ALARM_B; HAL_RTC_SetAlarm_IT(&hrtc_bsp, &sAlarm, FORMAT_BIN); } else if (sel_Alarm == BothAlarm) { sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc_bsp, &sAlarm, FORMAT_BIN); sAlarm.Alarm = RTC_ALARM_B; HAL_RTC_SetAlarm_IT(&hrtc_bsp, &sAlarm, FORMAT_BIN); } }
/* RTC init function */ void MX_RTC_Init(void) { RTC_TimeTypeDef sTime; RTC_DateTypeDef sDate; RTC_AlarmTypeDef sAlarm; /**Initialize RTC and set the Time and Date */ 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; HAL_RTC_Init(&hrtc); /* USER CODE BEGIN*/ rtc_backup_init(); if(rtc_check()==0) { sTime.Hours = 16; sTime.Minutes = 52; sTime.Seconds = 50; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.StoreOperation = RTC_STOREOPERATION_RESET; HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BIN); sDate.WeekDay = RTC_WEEKDAY_WEDNESDAY; sDate.Month = RTC_MONTH_APRIL; sDate.Date = 20; sDate.Year = 16; HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BIN); /**Enable the Alarm A */ sAlarm.AlarmTime.Hours = 16; sAlarm.AlarmTime.Minutes = 53; sAlarm.AlarmTime.Seconds = 1; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 1; sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); } /* USER CODE END*/ /**Enable the WakeUp */ HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 10240, RTC_WAKEUPCLOCK_RTCCLK_DIV16); }
/** * @brief Configure the current time and date. * @param None * @retval None */ static void RTC_AlarmConfig(void) { RTC_DateTypeDef sdatestructure; RTC_TimeTypeDef stimestructure; RTC_AlarmTypeDef salarmstructure; /*##-1- Configure the Date #################################################*/ /* Set Date: Tuesday February 18th 2014 */ sdatestructure.Year = 0x14; sdatestructure.Month = RTC_MONTH_FEBRUARY; sdatestructure.Date = 0x18; sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY; if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the Time #################################################*/ /* Set Time: 02:20:00 */ stimestructure.Hours = 0x02; stimestructure.Minutes = 0x20; stimestructure.Seconds = 0x00; stimestructure.TimeFormat = RTC_HOURFORMAT12_AM; stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-3- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 02:20:30 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; salarmstructure.AlarmTime.Hours = 0x02; salarmstructure.AlarmTime.Minutes = 0x20; salarmstructure.AlarmTime.Seconds = 0x30; salarmstructure.AlarmTime.SubSeconds = 0x56; if(HAL_RTC_SetAlarm_IT(&RtcHandle,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == USER_BUTTON_PIN) { /* Wait that user release the User push-button */ while(BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET){} HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN); /* Set the alarm to current time + 5s */ RTC_AlarmStructure.Alarm = RTC_ALARM_A; RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat; RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours; RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes; RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 5) % 60; RTC_AlarmStructure.AlarmDateWeekDay = 31; RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; if (HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry mainly when using more than one wakeup source this is to not miss any wakeup event. - Disable all used wakeup sources, - Clear all related wakeup flags, - Re-enable all used wakeup sources, - Enter the Standby mode. */ /*#### Disable all used wakeup sources: WKUP pin ###########################*/ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); /*#### Clear all related wakeup flags ######################################*/ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Enable WKUP pin */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /* Turn LED3 off */ BSP_LED_Off(LED3); /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); } }
static uint8_t rtc_check() { uint8_t hour,min; RTC_AlarmTypeDef sAlarm; RTC_DateTypeDef sdatestructureget; RTC_TimeTypeDef stimestructureget; if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2) { HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0x32F2); return 0; } else { //read time HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN); //set alarm /**Enable the Alarm A */ hour=stimestructureget.Hours; min=stimestructureget.Minutes+1; if(min>59) { min-=60; if(hour==23) hour=0; else hour++; } sAlarm.AlarmTime.Hours = hour; sAlarm.AlarmTime.Minutes = min; sAlarm.AlarmTime.Seconds = 1; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 1; sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); return 1; } }
/** * @brief Configure the current time and date. * @param None * @retval None */ static void RTC_AlarmConfig(void) { RTC_DateTypeDef sdatestructure; RTC_TimeTypeDef stimestructure; RTC_AlarmTypeDef salarmstructure; /*##-1- Configure the Date #################################################*/ /* Set Date: Tuesday February 18th 2014 */ sdatestructure.Year = 0x14; sdatestructure.Month = RTC_MONTH_FEBRUARY; sdatestructure.Date = 0x18; sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY; if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the Time #################################################*/ /* Set Time: 02:20:00 */ stimestructure.Hours = 0x02; stimestructure.Minutes = 0x20; stimestructure.Seconds = 0x00; if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-3- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 02:20:30 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmTime.Hours = 0x02; salarmstructure.AlarmTime.Minutes = 0x20; salarmstructure.AlarmTime.Seconds = 0x30; if(HAL_RTC_SetAlarm_IT(&RtcHandle,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == TAMPER_BUTTON_PIN) { HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN); /* Set the alarm to current time + 5s */ RTC_AlarmStructure.Alarm = RTC_ALARM_A; RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat; RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours; RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes; RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 5) % 60; RTC_AlarmStructure.AlarmDateWeekDay = 31; RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; if (HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Wait that user release the Tamper push-button */ while(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET){} /* Disable all used wakeup sources: WKUP pin */ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4); /* Clear all related wakeup flags */ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_WAKEUP_FLAG(PWR_WAKEUP_PIN_FLAG4); /* Enable WKUP pin */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4); /* Turn on LED1 */ BSP_LED_Off(LED1); /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); } }
void rtc_set_alarm(struct tm *ti, uint32_t subsecs) { RTC_AlarmTypeDef mAlarm; mAlarm.AlarmTime.Hours = ti->tm_hour; mAlarm.AlarmTime.Minutes = ti->tm_min; mAlarm.AlarmTime.Seconds = ti->tm_sec; mAlarm.AlarmTime.SubSeconds = subsecs; mAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT_24; mAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; mAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; mAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; mAlarm.AlarmDateWeekDay = 1; mAlarm.Alarm = RTC_ALARM_A; if (HAL_RTC_SetAlarm_IT(&RtcHandle, &mAlarm, RTC_FORMAT_BIN) != HAL_OK) { error("Set Alarm failed\n"); } }
//------------------------------------------------------- //crycle set min alarm,now 1 min void RTC_AlarmConfig(uint8_t hour,uint8_t min) { static RTC_AlarmTypeDef sAlarm; HAL_RTC_DeactivateAlarm(&hrtc,RTC_ALARM_A); read_rtc_status(); sAlarm.AlarmTime.Hours = hour; sAlarm.AlarmTime.Minutes = min; sAlarm.AlarmTime.Seconds = 1; sAlarm.AlarmTime.SubSeconds = 0; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 1; sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); }
void test_alarm(void) { RTC_AlarmTypeDef salarmstructure; /*##-2- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 02:20:30 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_None; salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; salarmstructure.AlarmTime.Hours = 0x00; salarmstructure.AlarmTime.Minutes = 0x00; salarmstructure.AlarmTime.Seconds = 0x05; salarmstructure.AlarmTime.SubSeconds = 0x00; if(HAL_RTC_SetAlarm_IT(&RTCHandle,&salarmstructure,FORMAT_BIN) != HAL_OK) { /* Initialization Error */ //Error_Handler(); } }
int main(void) { int i=5000; uint8_t ultrasoundEnableFlag; uint16_t voltage; /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config_8MHz(); //__HAL_RCC_PWR_CLK_ENABLE(); /* Initialize all configured peripherals */ MX_GPIO_Init(); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0); // HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 ); //open drain kimenet,pch fet, MX_ADC_Init(); //MX_I2C1_Init(); //MX_TIM3_Init(); MX_USART1_UART_Init(); GPIO_TIM3_OFF(); //HAL_Delay(100); MX_RTC_Init(); /* Enable Power Clock */ //__HAL_RCC_PWR_CLK_ENABLE(); uartTester(); // GPIO_TIM3_OFF(); //Feszültseg ellenörzése,sippogás----------------------------------------------------- voltage=voltage_read(ADC_CHANNEL_2,2); if(Full<voltage) batteryLevel=3; if(Medium < voltage && voltage<= Full) batteryLevel=2; if(Medium >= voltage) batteryLevel=1; HAL_Delay(1000); beeps(batteryLevel,1); PutString("Software version 2016.07.26.\n"); PutString("batteryLevel: "); PutNumber(batteryLevel); PutString("\n"); while(1){ //Feszültseg ellenörzése, paraméterek beállítása,fesz fvében------------------------ voltage=voltage_read(ADC_CHANNEL_2,2); if(Low > voltage){ if(UltraLow > voltage){ voltage=voltage_read(ADC_CHANNEL_2,2); if(UltraLow > voltage){ HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 1 ); //open drain kimenet,pch fet, HAL_PWR_EnterSTANDBYMode(); } } ultrasoundEnableFlag=0; sleepNum=LowVoltSleep; }else{ ultrasoundEnableFlag=1; sleepNum= linear(sleepNumMax,sleepNumMin, voltageMin,voltageMax,voltage); soundNum= linear(soundNumMin,soundNumMax,voltageMin,voltageMax,voltage); sounDelay=sDelay; } PutString("sleepNum"); PutNumber(sleepNum); PutString("\n"); PutString("soundNum"); PutNumber(soundNum); PutString("\n"); //Ultrahang generálás--------------------------------------------------------------- if(ultrasoundEnableFlag){ PutString("ultrasound(1)\n "); ultrasound(1); } //Sleep----------------------------------------------------------------------------- // HAL_ADC_MspDeInit(&hadc); HAL_Delay(10); PutString("sleep!\n"); HAL_NVIC_SetPriority(RTC_IRQn, 0, 0); HAL_NVIC_EnableIRQ(RTC_IRQn); for(uint8_t e=0 ; e < sleepNum ; e++){ HAL_RTC_GetTime(&hrtc,&sTim,RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &sDat, RTC_FORMAT_BIN); HAL_RTC_GetTime(&hrtc,&sTim,RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &sDat, RTC_FORMAT_BIN); PutNumber((uint32_t)sTim.Hours); PutString(":"); PutNumber((uint32_t)sTim.Minutes); PutString(":"); PutNumber((uint32_t)sTim.Seconds); PutString("\n"); if(sTim.Minutes==59){ sAlarm.AlarmTime.Minutes=0; if(sTim.Hours==23){ sAlarm.AlarmTime.Hours=0; }else{ sAlarm.AlarmTime.Hours=sTim.Hours+1; } }else{ sAlarm.AlarmTime.Minutes=sTim.Minutes+1; sAlarm.AlarmTime.Hours=sTim.Hours; } HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN); PutString("alarm: "); PutNumber((uint32_t)sAlarm.AlarmTime.Hours); PutString(":"); PutNumber((uint32_t)sAlarm.AlarmTime.Minutes); PutString(":"); PutNumber((uint32_t)sAlarm.AlarmTime.Seconds); PutString("\n"); SleepMode(); } HAL_NVIC_DisableIRQ(RTC_IRQn); } }
/** * @brief Get user info to setup an alarm * @param RTC handle * @note This function wait user info to setup the alarm. * @retval None */ static void LowPowerHandleAlarm(void) { enum { HOURS, MINUTES, SECONDS, END }; RTC_DateTypeDef currentdate; RTC_TimeTypeDef time, currenttime; RTC_AlarmTypeDef Alarm; uint8_t temp[16]; uint8_t exit = 0; uint8_t index = SECONDS; uint8_t position; /* Get the current time */ memset(&Alarm, 0x00, sizeof(RTC_AlarmTypeDef)); memset(&time,0x00,sizeof(RTC_TimeTypeDef)); memset(¤ttime,0x00,sizeof(RTC_TimeTypeDef)); /* Get the alarm time from user */ do { BSP_LCD_SetTextColor(LCD_COLOR_BLUE); sprintf((char *)temp, " %.2d:%.2d:%.2d", time.Hours, time.Minutes, time.Seconds); BSP_LCD_DisplayStringAt(0, 5 * Font24.Height, temp, NO_MODE); BSP_LCD_SetTextColor(LCD_COLOR_RED); switch(index) { case HOURS : position = 4; sprintf((char *)temp, "%.2d", time.Hours); break; case MINUTES: position = 7; sprintf((char *)temp, "%.2d", time.Minutes); break; case SECONDS : position = 10; sprintf((char *)temp, "%.2d", time.Seconds); break; } BSP_LCD_DisplayStringAt(position* Font24.Width, 5 * Font24.Height, temp, NO_MODE); user_event = JOY_NONE; user_action = 0; while(user_event == JOY_NONE); switch(user_event) { case JOY_UP : if(index == HOURS) { if( time.Hours == 23 ) time.Hours = 0; else time.Hours++; } if(index == MINUTES) { if(time.Minutes == 59 ) time.Minutes= 0; else time.Minutes++; } if(index == SECONDS) { if(time.Seconds == 59 ) time.Seconds =0; else time.Seconds++; } break; case JOY_DOWN : if(index == HOURS) { if (time.Hours == 0 ) time.Hours = 23; else time.Hours--; } if(index == MINUTES) { if(time.Minutes == 0) time.Minutes=59; else time.Minutes--; } if(index == SECONDS) { if(time.Seconds == 0) time.Seconds = 59; else time.Seconds--; } break; case JOY_RIGHT : if(index != SECONDS ) index++; break; case JOY_LEFT : if(index != HOURS ) index--; break; case JOY_SEL : exit = 1; break; } } while(exit == 0); HAL_RTC_GetTime(&RtcHandle, ¤ttime, FORMAT_BIN); HAL_RTC_GetDate(&RtcHandle, ¤tdate, FORMAT_BIN); time.SubSeconds = currenttime.SubSeconds; if((time.Seconds + currenttime.Seconds) > 60 ) time.Minutes++; time.Seconds = ((time.Seconds + currenttime.Seconds) % 60); if((time.Minutes + currenttime.Minutes) > 60 ) time.Hours++; time.Minutes = ((time.Minutes + currenttime.Minutes) % 60); time.Hours = ((time.Hours + currenttime.Hours) % 24); /* Set the alarm */ Alarm.Alarm = RTC_ALARM_A; Alarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; Alarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; Alarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; Alarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; Alarm.AlarmTime.TimeFormat = RTC_HOURFORMAT_24; Alarm.AlarmTime.Hours = time.Hours; Alarm.AlarmTime.Minutes = time.Minutes; Alarm.AlarmTime.Seconds = time.Seconds; if(HAL_RTC_SetAlarm_IT(&RtcHandle, &Alarm, FORMAT_BIN) != HAL_OK) { while(1); } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == TAMPER_BUTTON_PIN) { HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN); /* Set the alarm to current time + 5s */ RTC_AlarmStructure.Alarm = RTC_ALARM_A; RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat; RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours; RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes; RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 0x05) % 60; RTC_AlarmStructure.AlarmDateWeekDay = 0x31; RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES; RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE; /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry mainly when using more than one wakeup source this is to not miss any wakeup event: - Disable all used wakeup sources, - Clear all related wakeup flags, - Re-enable all used wakeup sources, - Enter the Standby mode. */ /*## Disable all used wakeup sources #####################################*/ /* Disable Wake-up timer */ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); /* Disable RTC Alarm */ HAL_RTC_DeactivateAlarm(&RTCHandle, RTC_ALARM_A); /*## Clear all related wakeup flags ######################################*/ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Clear the Alarm Flag */ __HAL_RTC_ALARM_CLEAR_FLAG(&RTCHandle, RTC_FLAG_ALRAF); /*## Re-enable all used wakeup sources ###################################*/ /* Set RTC alarm */ if(HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Enable WKUP pin */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /* Turn LED1 off */ BSP_LED_Off(LED1); /*## Enter Standby Mode ##################################################*/ HAL_PWR_EnterSTANDBYMode(); } if(GPIO_Pin == MFX_IRQOUT_PIN) { /* The different functionalities of MFX (TS, Joystick, SD detection, etc. ) can be configured in exti mode to generate an IRQ on given events. The MFX IRQ_OUT pin is unique and common to all functionalities, so if several functionalities are configured in exit mode, the MCU has to enquire MFX about the IRQ source (see BSP_IO_ITGetStatus). Communication with Mfx is done by I2C. Often the sw requires ISRs (irq service routines) to be quick while communication with I2C can be considered relatively long (hundreds of usec depending on I2C clk). Considering that the features for human interaction like TS, Joystick, SD detection don’t need immediate reaction, it is suggested to use POLLING instead of EXTI mode, in order to avoid "blocking I2C communication" on interrupt service routines */ /* Here an example of implementation is proposed: mix between pooling and exit: On ISR a flag is set (MfxIrqReceived), the main loop polls on the flag; Mcu communicates with Mfx only when the flag has been set. This is just an example: the users should choose they strategy depending on their application needs.*/ MfxExtiReceived = 1; } }
/*! * @brief start wake up alarm * @note alarm in RtcTimerContext.Rtc_Time + timeoutValue * @param timeoutValue in ticks * @retval none */ static void HW_RTC_StartWakeUpAlarm( uint32_t timeoutValue ) { uint16_t rtcAlarmSubSeconds = 0; uint16_t rtcAlarmSeconds = 0; uint16_t rtcAlarmMinutes = 0; uint16_t rtcAlarmHours = 0; uint16_t rtcAlarmDays = 0; RTC_TimeTypeDef RTC_TimeStruct = RtcTimerContext.RTC_Calndr_Time; RTC_DateTypeDef RTC_DateStruct = RtcTimerContext.RTC_Calndr_Date; HW_RTC_StopAlarm( ); DBG_GPIO_SET(GPIOB, GPIO_PIN_13); /*reverse counter */ rtcAlarmSubSeconds = PREDIV_S - RTC_TimeStruct.SubSeconds; rtcAlarmSubSeconds += ( timeoutValue & PREDIV_S); /* convert timeout to seconds */ timeoutValue >>= N_PREDIV_S; /* convert timeout in seconds */ /*convert microsecs to RTC format and add to 'Now' */ rtcAlarmDays = RTC_DateStruct.Date; while (timeoutValue >= SECONDS_IN_1DAY) { timeoutValue -= SECONDS_IN_1DAY; rtcAlarmDays++; } /* calc hours */ rtcAlarmHours = RTC_TimeStruct.Hours; while (timeoutValue >= SECONDS_IN_1HOUR) { timeoutValue -= SECONDS_IN_1HOUR; rtcAlarmHours++; } /* calc minutes */ rtcAlarmMinutes = RTC_TimeStruct.Minutes; while (timeoutValue >= SECONDS_IN_1MINUTE) { timeoutValue -= SECONDS_IN_1MINUTE; rtcAlarmMinutes++; } /* calc seconds */ rtcAlarmSeconds = RTC_TimeStruct.Seconds + timeoutValue; /***** correct for modulo********/ while (rtcAlarmSubSeconds >= (PREDIV_S+1)) { rtcAlarmSubSeconds -= (PREDIV_S+1); rtcAlarmSeconds++; } while (rtcAlarmSeconds >= SECONDS_IN_1MINUTE) { rtcAlarmSeconds -= SECONDS_IN_1MINUTE; rtcAlarmMinutes++; } while (rtcAlarmMinutes >= MINUTES_IN_1HOUR) { rtcAlarmMinutes -= MINUTES_IN_1HOUR; rtcAlarmHours++; } while (rtcAlarmHours >= HOURS_IN_1DAY) { rtcAlarmHours -= HOURS_IN_1DAY; rtcAlarmDays++; } if( RTC_DateStruct.Year % 4 == 0 ) { if( rtcAlarmDays > DaysInMonthLeapYear[ RTC_DateStruct.Month - 1 ] ) { rtcAlarmDays = rtcAlarmDays % DaysInMonthLeapYear[ RTC_DateStruct.Month - 1 ]; } } else { if( rtcAlarmDays > DaysInMonth[ RTC_DateStruct.Month - 1 ] ) { rtcAlarmDays = rtcAlarmDays % DaysInMonth[ RTC_DateStruct.Month - 1 ]; } } /* Set RTC_AlarmStructure with calculated values*/ RTC_AlarmStructure.AlarmTime.SubSeconds = PREDIV_S-rtcAlarmSubSeconds; RTC_AlarmStructure.AlarmSubSecondMask = HW_RTC_ALARMSUBSECONDMASK; RTC_AlarmStructure.AlarmTime.Seconds = rtcAlarmSeconds; RTC_AlarmStructure.AlarmTime.Minutes = rtcAlarmMinutes; RTC_AlarmStructure.AlarmTime.Hours = rtcAlarmHours; RTC_AlarmStructure.AlarmDateWeekDay = ( uint8_t )rtcAlarmDays; RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStruct.TimeFormat; RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE; RTC_AlarmStructure.Alarm = RTC_ALARM_A; RTC_AlarmStructure.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; RTC_AlarmStructure.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; /* Set RTC_Alarm */ HAL_RTC_SetAlarm_IT( &RtcHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN ); /* Debug Printf*/ DBG( HW_RTC_GetCalendarValue( &RTC_DateStruct, &RTC_TimeStruct ); );