2016-10-25 01:37 AM
Hi,
I am trying to use cubemx hal library for 1 second rtc interrupt. The call back function is called every time the ''minutes'' has changed. So it does not work for every 1 second. My rtc init and call back functions are below. void MX_RTC_Init(void) { /**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); /**Enable the Alarm A */ sAlarm.AlarmTime.Hours = 0x0; sAlarm.AlarmTime.Minutes = 0x0; sAlarm.AlarmTime.Seconds = 0x1; sAlarm.AlarmTime.SubSeconds = 0x0; sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_MINUTES; sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = 0x1; sAlarm.Alarm = RTC_ALARM_A; HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD); } void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) { HAL_RTC_GetAlarm(hrtc,&sAlarm,RTC_ALARM_A,FORMAT_BIN); //functions_1s(); if(sAlarm.AlarmTime.Seconds>58) { sAlarm.AlarmTime.Seconds=0; } else { sAlarm.AlarmTime.Seconds=sAlarm.AlarmTime.Seconds+1; } while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK){} } Any advise ??2016-10-26 03:47 AM
Hi rapid84,
It seems that you are using the LSI as RTC clock source. The Predivisors (127, 255) are dedicated for LSE use case. for LSI clock source case , you should use (127, 304) as (Asynch Prediv ,Synchro Prediv )-Hannibal-2016-10-26 06:19 AM
Hi,
No, I am using external 32Khz crystal. At startup, i have to set the second to ''0'' and call the set time function, like this: sTime.Seconds = 0 ; HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN); Otherwise the rtc alarm interrupt routine is not called until the second of the time has changed to ''0''. So i need to find the solution of calling the rtc alarm interrupt at startup whatever the second of time value is. Any advise ??2016-10-26 07:29 AM
I use an STM32L152 where I set the RTC alarm to trigger on subseconds = 0, or once per second. I don't use the cube or HAL so can't give a code example.
2016-11-04 02:34 AM
Hi rapid84,
Since you haven't shared your code, I don't know how you have configurate your RTC and calendar. I recommend to have a look , to the example in STM32CubeF4 ''RTC_Calendar'' at this path : STM32Cube_FW_F4_V1.13.0\Projects\STM324xG_EVAL\Examples\RTC\RTC_Calendar-Hannibal-2017-08-20 07:32 AM
hi
sAlarm.AlarmMask = RTC_ALARMMASK_All;i tested it
it works good