cancel
Showing results for 
Search instead for 
Did you mean: 

RTC on B-L475E-IOT01A.

At evening I set time 18-38-00, got it back, it was OK and left it to run. At morning I see the time 32-59-48.

My set-get functions

int RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
{
    if (hours < 24 && minutes < 60 && seconds < 60)
    {
        LL_RTC_DisableWriteProtection(RTC);
        
        if (Enter_RTC_InitMode() != RTC_OK) 
            return RTC_ERROR;
        
        LL_RTC_TIME_Config(RTC, LL_RTC_TIME_FORMAT_AM_OR_24, __LL_RTC_CONVERT_BIN2BCD(hours),
                                                             __LL_RTC_CONVERT_BIN2BCD(minutes),
                                                             __LL_RTC_CONVERT_BIN2BCD(seconds));
        
        if (Exit_RTC_InitMode() != RTC_OK) 
          return RTC_ERROR;
        
        LL_RTC_EnableWriteProtection(RTC); 
    }
    else
        return RTC_ERROR;
    
    return RTC_OK;
}
 
int RTC_GetTime( uint8_t *hours, uint8_t *minutes, uint8_t *seconds)
{
    *hours   = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_TIME_GetHour(RTC));
    *minutes = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_TIME_GetMinute(RTC)); 
    *seconds = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_TIME_GetSecond(RTC));
    
    return 0;
    
}

8 REPLIES 8

This happens when you set time >=13:00 while in 12-hour (am/pm) mode.

Read out and check the RTC registers.

JW

This option - LL_RTC_TIME_FORMAT_AM_OR_24 - isn't it suppose to take care of 24 hours format? What option should I use then?

I should set it this way? LL_RTC_SetHourFormat(RTC, LL_RTC_HOURFORMAT_24HOUR);

It'll fix the problem?

I don't use Cube/LL, look it up in its documentation if you feel you need to stick to Cube.

JW

Cube is not an option, I do not use it either, but LL is kinda trade off...

Cube is name of the "library" which has two parts - HAL and LL.

Maybe you confuse it with CubeMX, which is a program generating code which uses this "library".

In my opinion, LL is no tradeoff, it basically just renames the registers, so the only "benefit" from it is, that when you need to refer to the RM, you have to reverse-lookup the registers names. Cube's doxygen autovomited "manual" is not of much help, is it.

In this particular case, looking up what does LL_RTC_TIME_Config() reveals that it only modifies RTC_TR, and the Format12_24 parameter in its call simply sets value of RTC_TR.PM, i.e. the "current value of am/pm". But you probably have set incorrectly the FMT field in RTC_CR when setting up RTC, probably you used LL_RTC_Init() and did not fill in the struct used as parameter entirely or did not initialize that struct beforehand. LL_RTC_SetHourFormat() can be used as an afterthought but again looking it up it only writes the required FMT field in RTC_CR, so you need to go through the unprotect and initialization procedure as outlined in the RTC initialization and configuration subchapter of RTC chapter in RM.

JW

Thank you. It looks like the topic is off the agenda. RTC has a huge error - for a couple of hours it runs faster 2 minutes. It can be used in real applications.

Is it running from LSE?

JW

Yes. Actually I've managed to set it and now the error is reasonable. Now I should do some calibration or to think about precise crystal 5-10 ppm.