cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 RTC

mikes
Associate II
Posted on January 21, 2016 at 22:22

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 time

All I see is the RTC time since last power cycle so 0hrs 20mins XXseconds

I 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-hal
7 REPLIES 7
mikes
Associate II
Posted on January 27, 2016 at 15:56

Bump

engenharia2
Associate II
Posted on January 28, 2016 at 12:21

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);
}

mikes
Associate II
Posted on February 01, 2016 at 17:55

I updated sDate and that helped with setting the time.  I now have an issue on power up, or debug reset.

On power up initialization the functions I go through are from MXCube, and the HAL files...

 MX_RTC_Init();//generated by MXCube

inside this function the code jumps to 

 HAL_RTC_Init(&hrtc); //part of HAL, hrtc generated by MXCube

inside this function the code jumps to

RTC_EnterInitMode(hrtc);

inside this function I get stuck at

/* Wait till RTC is in INIT state and if Time out is reached exit */

    while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)

    {

      if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)

      {       

        return HAL_TIMEOUT;

      } 

    }

The RTC will timeout, and it never clears the write protect from the previous functions.  If I cycle power 3-5 times eventually it will make it through the function and the RTC will work properly.  Anyone else have an issue with the RTC on the STM32F030? or with STM32CubeMX version 4.7.0?

 

mikes
Associate II
Posted on February 15, 2016 at 15:06

bump

Posted on February 15, 2016 at 16:09

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mikes
Associate II
Posted on February 15, 2016 at 16:39

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.

mikes
Associate II
Posted on February 18, 2016 at 18:51

I finally got a chance to hop back on this and work on it.  I have found the solution to my issues.  For future reference, to anyone that has something similar, be sure to check your voltage levels very carefully.  I had my 5V, 3.3V, 2.5V,  and 12V regulators working properly on my board, but due to my diode configuration the 5V was going to the processor instead of the 3.3V.  Once I gave the proper power to the STM32 all of my issues went away.  Kind of embarrassed that I didn't catch this sooner.