2016-01-21 01:22 PM
I'm having an issue with the HAL_RTC_SetTime() function setting the RTC clock. I'm using MXCube to generate the RTC settings for IAR compiler.
I use the following code to set the clock to 1 hour sTime.Hours = 0x1; sTime.Minutes = 0x0; sTime.Seconds = 0x0; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.StoreOperation = RTC_STOREOPERATION_RESET; HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);When I use HAL_RTC_GetTime(&hrtc, sTime, FORMAT_BCD);HAL_RTC_GetDate(&hrtc, sTime, FORMAT_BCD); //must read date after timeAll I see is the RTC time since last power cycle so 0hrs 20mins XXsecondsI have tried using HAL_RTC_DeInit() followed by MX_RTC_INIT() but it always shows the RTC time from the last power cycle and not from the SetTime (even when MX_RTC_INIT is supposed to set the time to 0hr 0min 0sec 0subsec).Is there a special call I need to make before I set the time of the RTC? #no-hablo-hal2016-01-27 06:56 AM
Bump
2016-01-28 03:21 AM
Hello, you forgot to use the date variable sDatewhen you tried to read.Below is an example:
char str[25];
if ((HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN) == HAL_OK)
&& (HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK)) {
// Format time and date
memset(str, '\0', sizeof(str));
sprintf(str, ''Date: %02d/%02d/%04d - Time: %02d:%02d:%02d
'',
sDate.Date, sDate.Month, sDate.Year + 2000, sTime.Hours, sTime.Minutes, sTime.Seconds);
HAL_UART_Transmit(&huart2, str, strlen(str), 100);
}
2016-02-01 08:55 AM
2016-02-15 06:06 AM
bump
2016-02-15 07:09 AM
As it might becoming apparent, there isn't a lot of support here for HAL/F0 issues.
The answer from the forum would seem to be that others aren't having the problem, or simply aren't here.Is this on a custom board? What is the RTC using as a clock source?Perhaps we need to review this with a more complete context, where the code is condensed into a complete and clear example, and the hardware more completely defined. I'm not up to try and replicate the issue from scratch, so the more thorough the presentation, the more likely it is for others to surmise what is going on.2016-02-15 07:39 AM
This is a custom board, the RTC clock source is the internal LSI RC.
I wanted to mention another symptom while I am getting my code in order to attach it to my next post.I have found that if I wait 5-10 seconds after removing power, before reapplying the power, the RTC will function properly about 75% of the time. If I turn off the power and reapply it under 5 seconds. I get stuck in the RTC_init loop and then timeout. The code goes into my main and works, but the RTC portion does not. When reapplying power on power cycle in under 5 seconds it fails to work about 90% of the time.2016-02-18 09:51 AM