HAL库
RTC_HandleTypeDef hrtc;
RTC_TimeTypeDef sTime = {0};
RTC_AlarmTypeDef sAlarm = {0};
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] RTC中断初始化,用于睡眠定时唤醒
* @param
* @retval
*/
void rtc_INT_init(uint16_t ms)
{
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24; //LL_RTC_SetHourFormat(RTC_TypeDef *RTCx, uint32_t HourFormat);
hrtc.Init.AsynchPrediv = 36; //LL_RTC_SetAsynchPrescaler(RTC_TypeDef *RTCx, uint32_t AsynchPrescaler);
hrtc.Init.SynchPrediv = ms; //LL_RTC_SetSynchPrescaler(RTC_TypeDef *RTCx, uint32_t SynchPrescaler);
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; //
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; //LL_RTC_DisableOutRemap(RTC_TypeDef *RTCx);
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;//LL_RTC_SetOutputPolarity(RTC_TypeDef *RTCx, uint32_t Polarity);
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; //LL_RTC_SetAlarmOutputType(RTC_TypeDef *RTCx, uint32_t Output);
HAL_RTC_Init(&hrtc);
/** Initialize RTC and set the Time
*/
sTime.Hours = 0x08; //LL_RTC_TIME_SetHour(RTC_TypeDef *RTCx, uint32_t Hours)
sTime.Minutes = 0x30; //LL_RTC_TIME_SetMinute(RTC_TypeDef *RTCx, uint32_t Minutes)
sTime.Seconds = 0x10; //LL_RTC_TIME_SetSecond(RTC_TypeDef *RTCx, uint32_t Seconds)
sTime.TimeFormat = RTC_HOURFORMAT12_AM; //LL_RTC_TIME_SetFormat(RTC_TypeDef *RTCx, uint32_t TimeFormat);
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; //LL_RTC_TIME_DisableDayLightStore(RTC_TypeDef *RTCx)
sTime.StoreOperation = RTC_STOREOPERATION_RESET; //
HAL_RTC_SetTime(&hrtc,&sTime,RTC_FORMAT_BCD);
/** Enable the Alarm A
*/
sAlarm.Alarm = RTC_ALARM_A; //LL_RTC_ALMA_Enable(RTC_TypeDef *RTCx)
sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; //LL_RTC_ALMA_SetWeekDay(RTC_TypeDef *RTCx, uint32_t WeekDay)
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; //LL_RTC_ALMA_SetMask(RTC_TypeDef *RTCx, uint32_t Mask)
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;//LL_RTC_ALMA_SetSubSecondMask(RTC_TypeDef *RTCx, uint32_t Mask)
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; //LL_RTC_ALMA_SetTimeFormat(RTC_TypeDef *RTCx, uint32_t TimeFormat);
sAlarm.AlarmTime.Hours = 0x08; //LL_RTC_ALMA_SetHour(RTC_TypeDef *RTCx, uint32_t Hours)
sAlarm.AlarmTime.Minutes = 0x30; //LL_RTC_ALMA_SetMinute(RTC_TypeDef *RTCx, uint32_t Minutes)
sAlarm.AlarmTime.Seconds = 0x10; //LL_RTC_ALMA_SetSecond(RTC_TypeDef *RTCx, uint32_t Seconds)
sAlarm.AlarmTime.SubSeconds = 1; //LL_RTC_ALMA_SetSubSecond(RTC_TypeDef *RTCx, uint32_t Subsecond)
HAL_RTC_SetAlarm_IT(&hrtc,&sAlarm,RTC_FORMAT_BCD);
HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_IRQn);
__HAL_RCC_RTC_ENABLE(); //LL_RTC_EnableIT_ALRA(RTC_TypeDef *RTCx)
}
void RTC_IRQHandler(void)
{
/* USER CODE BEGIN RTC_IRQn 0 */
/* USER CODE END RTC_IRQn 0 */
HAL_RTC_AlarmIRQHandler(&hrtc);
/* USER CODE BEGIN RTC_IRQn 1 */
/* USER CODE END RTC_IRQn 1 */
}
uint32_t count=0;
/* USER CODE BEGIN 1 */
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
count++;
debug_print(0, "Enter Count%d\r\n",count);
HAL_RTC_SetTime(hrtc, &sTime, RTC_FORMAT_BCD);
}
|