Content originally posted in LPCWare by MikeSimmonds on Fri Oct 31 10:35:53 MST 2014
I am using the LPC1778 (but I guess the the RTC block is similar).
Also I do not use NXP CMSIS or LPCOpen libraries so I find it difficult to see exactly
which RTC hardware registers you are changing and what the changes are.
I suspect however that you are re-initialising the RTC at each reset rather than checking
to see it it is already setup (maintained by the battery)
The RTC init should first check the RTC_AUX register (offset 5C hex) an look at bit 4 (RTC_OSCF) to see if
the RTC oscillator has stopped (or has never been started).
[After reading/saving this bit, you must write a one back to the same register to clear the flag regardless.]
If the bit was set (one) the RTC is not running and needs to be setup:
Set CCR (Clock Control Register) to 0x12 (disable calibration, reset divisor, disable counting)
write date/time values [Default to some standard eg midnight 1/1/2000?]
Set RTC CCR to 0x11 (disable calibration, release divisor, enable counting)
Otherwise, DO NOTHING -- The RTC is running.
You will have to translate these register accesses to conform with the CMSIS/LPC Open headers etc.
But that is how to maintain the time and date across power cycles/resets [Given a permanent battery supply].
Cheers (mine's a pint) Mike,