If you want the RTC to retain the time and date, you need to power VBACKUP pin separately (not VDDD) and possibly using a coin-cell battery. When device has active VDDD available, BACKUP domain (RTC) runs from VDDD and when VDDD is removed, it switches to VBACKUP supply.
In PSoC Creator, you need to select “Dedicated Supply” as the source for VBACKUP to avoid reset of RTC on POR or XRES.
Time reset on Start has to be used with PSoC Creator wrapper RTC_Start(). It has no influence on Cy_RTC_Init() PDL function.
Every time reset happens, you might be calling Cy_RTC_Init which resets the RTC values to default values. If you want to avoid that Cy_RTC_Init has to be called only once. So you can implement is the following logic:
if(rtc_initialialized == 0) //rtc_initialized is a custom variable in flash
//rtc_initalised is true; write 1 in flash
Where can I find the VBACKUP pin?
I spent some time reading the manuals, and I thought I'd try using Switch SW7 to set the Vbackup supply connection of PSoC 6 MCU to the super-capacitor. But then, I can't program the device:
Erasing of Main Flash...
Erasing of Main Flash Failed
EraseAll API returned: Error code 0x74CCA400: Unknown SROM status code
Error: dbg.M0023: There was an error while programming the device: PSoC Programmer reported error (100 - EraseAll API returned: Error code 0x74CCA400: Unknown SROM status code)
Is there a way around that?
I was able to get the RTC to keep time between resets by avoiding calling Cy_RTC_Init. But if I remove the USB power it goes back to
Date 01/01/00 Time 00:00:00.
The super capacitor needs to be charged to the required voltage initially before setting the SW7 switch to Super Cap mode.
This is achieved using the API Cy_SysPm_BackupSuperCapCharge(CY_SYSPM_SC_CHARGE_ENABLE);
You can use one of the backup registers present (retained as long as backup domain is powered) instead of using the flash to initialize the RTC block only once.
Please refer to the following thread that explains the steps in detail. There is also a project attached in the end for your reference.
But if you are using a battery, then Cy_SysPm_BackupSuperCapCharge(CY_SYSPM_SC_CHARGE_ENABLE); should not be called. External circuitry should take care of battery charging.
Thanks, I now have it working the way I want it to. I found the missing link in the thread that you referenced: I had to change External PMIC Output (under System settings) to Enabled.
To paraphrase someone famous, "Nobody knew [the RTC and VBACKUP] could be so complicated."