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_HOSTINGextern 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 }}
You have the RTC configure to use the LOCO, not Sub-oscillator in the configuration of the RTC driver.
In the project you attached, in the configuration of the RTC driver, the RTC is set to use the LOCO, not the Sub-Clock.
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
You have the RTC driver set to configure the HW in the open() call -
This means the RTC will be initailised each time RTC_Open() is called :-
hai jeremy!!!....
Thanks for your support!.. Already i configured RTC hardware in open call -yes only. checked in above condition same problem only facing and also checked In No condition . kindly suggest me the solution after power down rtc should show current updated value
You also have to enable Voltage monitor 0 to use the VBATT Battery Backup Function :-
12.3.2 VBATT Battery Power Supply Switch UsageThe battery power supply switch can switch the power supply from the VCC pin to the VBATT pin when the voltagebeing applied to the VCC pin drops. When the voltage rises, this switch changes the power supply from the VBATT pinto the VCC pin.
Note: You must enable voltage monitor 0 resets to use the battery backup function. Voltage monitor 0 level must behigher than the VBATT switch level.
Also, if you have the CGC driver set to configure the subclock drive on reset,
the subclock will be stopped at reset in R_CGC_init() :-
/** SubClock will stop only if configurable setting is Enabled */#if (CGC_CFG_SUBCLOCK_AT_RESET_ENABLE == 1) r_cgc_clock_stop(gp_system_reg, CGC_CLOCK_SUBCLOCK); // stop SubClock CGC_ERROR_RETURN((SSP_SUCCESS == r_cgc_wait_to_complete(CGC_CLOCK_SUBCLOCK, CGC_CLOCK_CHANGE_STOP)), SSP_ERR_HARDWARE_TIMEOUT); r_cgc_delay_cycles(gp_system_reg, CGC_CLOCK_SUBCLOCK, SUBCLOCK_DELAY); // Delay for 5 SubClock cycles. r_cgc_subclock_drive_set(gp_system_reg, CGC_CFG_SUBCLOCK_DRIVE); // set the SubClock drive according to the configuration#endif
Thanks for your support!.. where i have to enable the voltage monitor 0 . in which driver it available .
Voltage monitor 0 is configured in the BSP tab of the configurator
Thanks for your support!.. i have checked your above suggestion still same problem only facing . kindly check my below configurations and and above message i have updated the cgc ,rtc configuration code for your reference .
If the RTC has stopped after power has been reapplied, I would check the VBATT power supply.
hai!.
Kindly update me the solution to solve this problem.
The project in the link works on the S7G2_DK board, the RTC keeps running on VBATT when the power is removed from Vcc.
renesasrulz.com/.../download
rtc_test_.zip
Thanks for your support!.. i have checked your above example code in my device after power off rtc gets reset ,same problem facing . After power off super capacitor providing 2.8 v to vbat pin. kindly update me the solution to solve this problem. facing this problem last three weekS and also i have atteched my rtc and lcd code which i have tested in my custom board s7g2 100 pin IC, kindly take it for your reference.
sry i didnt get your point
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.
Have you looked at my example?
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.