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 Reply
  • You also have to enable Voltage monitor 0 to use the VBATT Battery Backup Function :-

    12.3.2 VBATT Battery Power Supply Switch Usage
    The battery power supply switch can switch the power supply from the VCC pin to the VBATT pin when the voltage
    being applied to the VCC pin drops. When the voltage rises, this switch changes the power supply from the VBATT pin
    to the VCC pin.


    Note: You must enable voltage monitor 0 resets to use the battery backup function. Voltage monitor 0 level must be
    higher than the VBATT switch level.

Children