RTC not working on power down

hai!!

          i  am using s7g2 100 pin  custom board, my RTC working fine , but when i off and ON the power,RTC  not reading current updated value, it goes  to initialized value only. In below i have updated my code for your reference kindly suggest me the solution what should update for further process.

#include "RTC_thread.h"
#include<stdio.h>
#include"flash_header.h"
#define SEMI_HOSTING
extern char rtc_time_s[10],calender_s[8],rtc_time_hr_s[2],rtc_time_min_s[2],rtc_time_sec_s[2],rtc_time_year_s[2],rtc_time_month_s[2],rtc_time_day_s[2],rtc_time_wday_s[1],rtc_time_hr_min_s[10];
char rtc_year_flag,rtc_month_flag,rtc_day_flag,rtc_hour_flag,rtc_min_flag,rtc_sec_flag,rtc_wday_flag;

char extra_symbols[5]={':','-','.'};
extern int rtc_hour_file_ex=0,rtc_minutes_file_ex=0,rtc_year_file_ex=0,rtc_sec_file_ex=0;
int clock_sett_hr_s_file_ex,clock_sett_min_s_file_ex,clock_sett_sec_s_file_ex,clock_sett_year_s_file_ex,clock_sett_month_s_file,clock_sett_day_s_file_ex;
int pfc_input1;
extern int rtc_hr,rtc_min,rtc_sec,rtc_year,rtc_month,rtc_day,rtc_wday;
extern float rtc_hr_min;
float rtc_hr_min_add;
//ssp_err_t err;
void RTC_thread_entry(void)
{
rtc_time_t get_time;
ssp_err_t err;
err = g_rtc0.p_api->open (g_rtc0.p_ctrl, g_rtc0.p_cfg);
if (err == SSP_SUCCESS)
{
err = g_rtc0.p_api->periodicIrqRateSet (g_rtc0.p_ctrl, RTC_PERIODIC_IRQ_SELECT_1_SECOND);
if (err == SSP_SUCCESS)
{
err = g_rtc0.p_api->calendarCounterStart (g_rtc0.p_ctrl);
if (err == SSP_SUCCESS)
{
err = g_rtc0.p_api->irqEnable (g_rtc0.p_ctrl, RTC_EVENT_PERIODIC_IRQ);
}
}
err = SSP_SUCCESS;
rtc_time_t set_time = { 0 };

set_time.tm_hour = 11;
set_time.tm_min = 00;
set_time.tm_sec = 02;
set_time.tm_year = 2021 - 1900;
set_time.tm_mon = 2;
set_time.tm_mday = 10;
/*rtc_hr=atoi(clock_sett_hr_s_file_ex);
rtc_min=atoi(clock_sett_min_s_file_ex);
rtc_sec=atoi(clock_sett_sec_s_file_ex);
rtc_year=atoi(clock_sett_year_s_file_ex);
rtc_month=atoi(clock_sett_month_s_file);
rtc_day=atoi(clock_sett_day_s_file_ex);
*/
/* set_time.tm_hour = clock_sett_hr_s_file_ex;
set_time.tm_min =flash_data.flash_data_from_firmware_to_guix[47];
set_time.tm_sec =flash_data.flash_data_from_firmware_to_guix[48];
set_time.tm_year =2021- 1900;
set_time.tm_mon =2;
set_time.tm_mday = 9;
set_time.tm_wday=1;*/
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}

while (1)
{
if(rtc_hour_flag==1)
{
rtc_time_t set_time = { 0 };

set_time.tm_hour = flash_data.flash_data_from_guix_to_firmware[46];
set_time.tm_min = rtc_min;
set_time.tm_sec = rtc_sec;
set_time.tm_year =rtc_year;
set_time.tm_mon = rtc_month;
set_time.tm_mday = rtc_day;
tx_thread_sleep (1);
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
rtc_hour_flag=0;
}
else if(rtc_min_flag==1)
{
rtc_time_t set_time = { 0 };
set_time.tm_hour = rtc_hr;
set_time.tm_min = flash_data.flash_data_from_guix_to_firmware[47];
set_time.tm_sec = rtc_sec;
set_time.tm_year =rtc_year;
set_time.tm_mon = rtc_month;
set_time.tm_mday = rtc_day;
tx_thread_sleep (1);
rtc_min_flag=0;
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}
else if(rtc_sec_flag==1)
{
rtc_time_t set_time = { 0 };
set_time.tm_hour = rtc_hr;
set_time.tm_min = rtc_min;
set_time.tm_sec = flash_data.flash_data_from_guix_to_firmware[48];
set_time.tm_year =rtc_year;
set_time.tm_mon = rtc_month;
set_time.tm_mday = rtc_day;
tx_thread_sleep (1);
rtc_sec_flag=0;
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}
else if(rtc_year_flag==1)
{
rtc_time_t set_time = { 0 };
set_time.tm_hour = rtc_hr;
set_time.tm_min = rtc_min;
set_time.tm_sec = rtc_sec;
set_time.tm_year = flash_data.flash_data_from_guix_to_firmware[42]- 1900;
set_time.tm_mon = rtc_month;
set_time.tm_mday = rtc_day;
tx_thread_sleep (1);
rtc_year_flag=0;
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}
else if(rtc_month_flag==1)
{
rtc_time_t set_time = { 0 };
set_time.tm_hour = rtc_hr;
set_time.tm_min = rtc_min;
set_time.tm_sec = rtc_sec;
set_time.tm_year =rtc_year;
set_time.tm_mon = flash_data.flash_data_from_guix_to_firmware[43];
set_time.tm_mday = rtc_day;
tx_thread_sleep (1);
rtc_month_flag=0;
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}
else if(rtc_day_flag==1)
{
rtc_time_t set_time = { 0 };
set_time.tm_hour = rtc_hr;
set_time.tm_min = rtc_min;
set_time.tm_sec = rtc_sec;
set_time.tm_year = rtc_year;
set_time.tm_mon = rtc_month;
set_time.tm_mday = flash_data.flash_data_from_guix_to_firmware[44];
tx_thread_sleep (1);
rtc_day_flag=0;
err = g_rtc0.p_api->calendarTimeSet (g_rtc0.p_ctrl, &set_time, true);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}
}

else{
}
err =g_rtc0.p_api->calendarTimeGet (g_rtc0.p_ctrl, &get_time);
if( err != SSP_SUCCESS)
{
__BKPT(1);
}

sprintf(rtc_time_hr_s,"%02d", get_time.tm_hour);
sprintf(rtc_time_min_s,"%02d", get_time.tm_min);
sprintf(rtc_time_sec_s,"%02d", get_time.tm_sec);
sprintf(rtc_time_year_s,"%02d", get_time.tm_year);
sprintf(rtc_time_month_s,"%02d", get_time.tm_mon);
sprintf(rtc_time_day_s,"%02d", get_time.tm_mday);
sprintf(rtc_time_hr_min_s,"%02d%c%02d", get_time.tm_hour,extra_symbols[2],get_time.tm_min);

rtc_hr=atoi(rtc_time_hr_s);
rtc_min=atoi(rtc_time_min_s);
rtc_sec=atoi(rtc_time_sec_s);
/////// year 2021-1900= 121 here ignoring first decimal 1 so swapping done in below

rtc_time_year_s[0]=rtc_time_year_s[1];
rtc_time_year_s[1]=rtc_time_year_s[2];
rtc_year=atoi(rtc_time_year_s);
rtc_month=atoi(rtc_time_month_s);
rtc_day=atoi(rtc_time_day_s);
rtc_hr_min=atof(rtc_time_hr_min_s);
rtc_hr_min=rtc_hr_min+0.001;


sprintf(rtc_time_s,"%02d%c%02d%c%02d", get_time.tm_hour,extra_symbols[0],get_time.tm_min,extra_symbols[0],get_time.tm_sec);
// sprintf(calender_s,"%02d%c%02d%c%02d", get_time.tm_mday,extra_symbols[1],get_time.tm_mon,extra_symbols[1],get_time.tm_year);
sprintf(calender_s,"%02d%c%02d%c%02d", get_time.tm_mday,extra_symbols[1],get_time.tm_mon,extra_symbols[1],rtc_year);
tx_thread_sleep (100); // delay 100 x 10ms = 1s and then read the time again to test
}
}

Parents
  • Hi,

    Try using Sub-Clock while not on debugging mode and check,

    We had a similar issue which was solved by this.

    Regards,

    Surojit

  • hai !.

      thanks for reply!.. I checked which you have suggested, same problem i am facing . i am using super capacitor during power down mode from super capacitor 2.7v is going to rtc

  • yes, just for testing purpose only i used LOCO beforei tested in sub clock .kindly find  my new attachment for your reference RTC_TEST_AAD.zip

  • If the project I posted doesn't work on your hardware,  I cannot rule out the issue you are seeing is caused by a hardware issue with your board.

  • 2021.rtc_test__working.zip

    hai!...

              I have attached my schematic and code in above.kindly take it for your reference,and revert me  is it correct or have to make any configuration settings  or schematic change should be done or not.

  • In the attached project you still have the RTC driver set to configure the RTC Hardware n the Open() call :- 

    this means the RTC will be stopped when Open API is called, this is not how I had the RTC driver configured in the sample project I posted.

  • hai!.....

              IF I configured the rtc hardware in open() call- NO , my controller is not reading the values at power on time and you posted code is not get Building in my IDE.

  • yes, i have looked your shared project and same configuration made in my project but problem not solved kindly check my entire configuration and code for your reference.

  • My code only configures and starts the RTC if the RTC is not running, if it is running on return from VBATT power only the RTC open is called, it is not configured or started, e.g. :-

        err = g_rtc0.p_api->open(g_rtc0.p_ctrl, g_rtc0.p_cfg);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

        err = g_rtc0.p_api->infoGet(g_rtc0.p_ctrl, &rtc_status);
        if (SSP_SUCCESS != err)
        {
            while(1);
        }

        if ((RTC_STATUS_STOPPED == rtc_status.status))
        {
                err = g_rtc0.p_api->configure(g_rtc0.p_ctrl, NULL); //p_extended currently not used.
                if (SSP_SUCCESS != err)
                {
                    while(1);
                }

                /* Saturday 1st Jan 2000 00:00:00 */
                calendar_set_time.tm_hour = 0;
                calendar_set_time.tm_isdst = 0;
                calendar_set_time.tm_mday = 1;
                calendar_set_time.tm_min = 0;
                calendar_set_time.tm_mon = 0;
                calendar_set_time.tm_sec = 0;
                calendar_set_time.tm_wday = 6;
                calendar_set_time.tm_yday = 0;
                calendar_set_time.tm_year = 2000 - 1900;

                err = g_rtc0.p_api->calendarTimeSet(g_rtc0.p_ctrl, &calendar_set_time, true);
                if (SSP_SUCCESS != err)
                {
                    while(1);
                }

        else
        {

             /* RTC is running, don't reconfigure it */

        }

    In my project the RTC driver does not initalise the RTC hardware in the call to Open() (configuring the RTC HW in the call to open() will stop the RTC and reset the registers, this is not the behaviour that is required when running the RTC on VBATT) :-

    The CGC driver does not set the driver strength (as this will stop the Sub-Clock and introduce inaccuracy into the RTC) :-

    and the Voltage 0 monitoring circuit is enabled (this is required when suing the RTC in battery backup) :-

    You need to look at my project and understand how it works, and implement something similar in your project.

  • hai!..

            During power down mode my super capacitor providing 2.7v to Vbatt pin, This voltage is sufficient for rtc operation?

  • I have an HE-PMI board. I put in a battery and my clock remembers the time when it wakes up... but it doesn't count time while the power is off.

    I tried changing the SSC to not configure the clock on open, but that didn't help. Do I need to configure a subclock, like you have here? Or is the HE-PMI just not set up to maintain the clock from battery (which seems unlikely given it has a battery slot)?

  • Only the subclock operates in battery backup operation, if you want the RTC to continue to count in battery backup mode, the RTC needs to be operating from the subclock, not the LOCO :-

  • I see. I didn't expect supporting the battery to be quite so involved, but thank goodness you are here to tell us the handful of secret steps that make it easy.

    Although I don't use Eclipse, I found I can open the configuration.xml file with the synergy_standalone.exe (ironically found in the SSC/eclipse directory) and view your configuration. However, that didn't help as much as I'd hoped; because it's for a DK board I can't tell what you've changed, so I had to rely on the screenshots you highlighted.

    I found the CGC driver already in my HAL stack (after fruitlessly trying to add one as a new stack) . I'm assuming your main oscillator wait time is different than mine because they're different boards. Since you didn't highlight it, I didn't change it.

    I found the OFS1 settings by clicking the BSP tab (this was not obvious to me at first).

    I added the initialization code you provided after adapting it to my circumstances. I didn't use the battery backed RAM markers, though; it's quite likely people will start my device without a battery, so I just have to reconfigure it then. (Is a 2 second delay really necessary? That seems like a long time.)

    And it works. YAY! Once again Jeremy rides to the rescue.

    However, I left my board powered on last night (when it was running off of LOCO), and when I came in this morning it had lost 2 minutes over the course of 15 hours. Not good! I will try it again tonight and see if the sub-clock drive is better.

  • I think the load capacitors on the 32kHz sub oscillator crystal are incorrect on the PE-HMI, so they will pull the frequency of the 32.768kHz sub oscillator away from the centre frequency. See these 2 posts :-

    https://renesasrulz.com/synergy/f/synergy---forum/14642/rtc-s5d9/46551#46551

    https://renesasrulz.com/synergy/f/synergy---forum/15511/rtc-power-down-not-work/49681#49681

    The sub oscillator crystal used on the PE-HMI is ABS07-32.768KHZ-T which specifies CL as 12.5pF (i.e. the total load capacitance seen by the crystal should be 12.5pF), the circuit on the PE-HMI is :-

  • I used a 2 second wait time before using the sub oscillator because 32kHz crystals can take a while to stabilise. The S7G2 HW manual has this note on Table 60.14 :-

    Note 1. When setting up the sub-clock oscillator, ask the oscillator manufacturer for an oscillation evaluation and use the
    results as the recommended oscillation stabilization time. After changing the setting in the SOSCCR.SOSTP bit
    to start sub-clock operation, only start using the sub-clock oscillator after the sub-clock oscillation stabilization
    time elapses with an adequate margin. Two times the oscillation wait time is recommended.

Reply
  • I used a 2 second wait time before using the sub oscillator because 32kHz crystals can take a while to stabilise. The S7G2 HW manual has this note on Table 60.14 :-

    Note 1. When setting up the sub-clock oscillator, ask the oscillator manufacturer for an oscillation evaluation and use the
    results as the recommended oscillation stabilization time. After changing the setting in the SOSCCR.SOSTP bit
    to start sub-clock operation, only start using the sub-clock oscillator after the sub-clock oscillation stabilization
    time elapses with an adequate margin. Two times the oscillation wait time is recommended.

Children
No Data