RTC strange data with calendarTimeGet

Hi

We have a project with a custom pcb with a micro synergy R7FS5D97C.

We are using SSP version 1.7.5 and we are working with e2studio v7.8.0.

We are trying to work with the micro's RTC.

The code to initialize is the next:

subclk_st1 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_INACTIVE = 400

subclk_start = g_cgc.p_api->clockStart(CGC_CLOCK_SUBCLOCK, NULL); //This api return SSP_SUCCESS = 0

subclk_st2 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_ACTIVE = 401
R_BSP_SoftwareDelay(1900, BSP_DELAY_UNITS_MILLISECONDS); //Wait while subclock stabilizes

subclk_st3 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_ACTIVE = 401

g_rtc_init1 = g_rtc_clock.p_api->open(g_rtc_clock.p_ctrl, g_rtc_clock.p_cfg); //This api return SSP_SUCCESS = 0
if (g_rtc_init1 != SSP_SUCCESS) return g_rtc_init1;

R_RTC->RCR2_b.HR24 = 1; // Set 24 hour mode via direct reg access

subclk_st4 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_ACTIVE = 401

g_rtc_init2 = g_rtc_clock.p_api->periodicIrqRateSet(g_rtc_clock.p_ctrl, RTC_PERIODIC_IRQ_SELECT_1_SECOND); //This api return SSP_SUCCESS = 0
if (g_rtc_init2 != SSP_SUCCESS) return g_rtc_init2;

subclk_st5 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_ACTIVE = 401

g_rtc_init3 = g_rtc_clock.p_api->calendarCounterStart(g_rtc_clock.p_ctrl); //This api return SSP_SUCCESS = 0
if (g_rtc_init3 != SSP_SUCCESS) return g_rtc_init3;

subclk_st6 = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK); //This api return SSP_ERR_CLOCK_ACTIVE = 401

g_rtc_init4 = g_rtc_clock.p_api->irqEnable(g_rtc_clock.p_ctrl, RTC_EVENT_PERIODIC_IRQ); //This api return SSP_SUCCESS = 0
if (g_rtc_init4 != SSP_SUCCESS) return g_rtc_init4;

 

The configuration for the RTC driver is:

 

In the g_rtc_callback we have the next code:

if (RTC_EVENT_PERIODIC_IRQ == p_args->event)
{
if (_io_get_GLed_isOn) { _io_set_GLed_off; } //this led blinks every second correctly
else { _io_set_GLed_on; }

g_rtc_get_err = g_rtc_clock.p_api->calendarTimeGet(g_rtc_clock.p_ctrl, &g_system_time); //This api return SSP_SUCCESS = 0

}

Now when we paint g_system_time in the lcd with this function:
tft_bf_count = (uint16_t)sprintf ((char *)tft_buffer, "%i / %i / %i %02i : %02i : %02i ", g_system_time.tm_mday, (g_system_time.tm_mon + 1), (g_system_time.tm_year + 1900), g_system_time.tm_hour, g_system_time.tm_min, g_system_time.tm_sec);

the result in the screen is: 16 / 6 / 2020 13:160:120 where minutes and seconds have inconsistent values above 59.

 

Can someone help us? give us a clue that we are doing wrong.

 

Thanks

  • Hi Hanton,

    It looks like your code is missing call to "configure" function and the property to invoke it automatically during "open" is also disabled. "configure" call sets up few crucial settings like: clock source, 24 hour mode and calendar mode. My guess is that RTC is left in the decimal mode which is why you're seeing weird values which appear outside of the standard 0-59 range used in calendar mode. I highly recommend calling "configure" after "open" to address this issue.

    Here's a small snippet of the RTC setup from one of my projects:

       UINT status;

       status = g_rtc.p_api->open(g_rtc.p_ctrl, g_rtc.p_cfg);
       if (SSP_SUCCESS != status)
       {
           __BKPT(0);
       }

       rtc_info_t rtc_info = {0};

       status = g_rtc.p_api->infoGet(g_rtc.p_ctrl, &rtc_info);
       if (SSP_SUCCESS != status)
       {
           __BKPT(0);
       }

       if (RTC_CLOCK_SOURCE_SUBCLK == g_rtc.p_cfg->clock_source)
       {
           status = g_cgc.p_api->clockCheck(CGC_CLOCK_SUBCLOCK);
       }

       else
       {
           status = g_cgc.p_api->clockCheck(CGC_CLOCK_LOCO);
       }

       if (RTC_STATUS_STOPPED == rtc_info.status ||
           SSP_ERR_CLOCK_INACTIVE == status)
       {
           status = g_rtc.p_api->configure(g_rtc.p_ctrl, NULL);
           if (SSP_SUCCESS != status)
           {
               tx_thread_sleep(5);

               status = g_rtc.p_api->configure(g_rtc.p_ctrl, NULL);
               if (SSP_SUCCESS != status)
               {
                   __BKPT(0);
               }
           }

           status = g_rtc.p_api->calendarCounterStart(g_rtc.p_ctrl);
           if (SSP_SUCCESS != status)
           {
               __BKPT(0);
           }
       }

       status = g_rtc.p_api->periodicIrqRateSet(g_rtc.p_ctrl, RTC_PERIODIC_IRQ_SELECT_1_SECOND);
       if (SSP_SUCCESS != status)
       {
           __BKPT(0);
       }

       status = g_rtc.p_api->irqEnable(g_rtc.p_ctrl, RTC_EVENT_PERIODIC_IRQ);
       if (SSP_SUCCESS != status)
       {
           __BKPT(0);
       }

    Regards

  • In reply to Renesas Karol:

    Hi Karol

    Thanks a lot for the answer.

    It seems work properly .

    Regards