lpcware

RTC time lost after power failure on LPC4357

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by amey_pandit on Fri Oct 31 02:05:18 MST 2014
Hi Guys

I am, using a LPC4357 module on a EA base board (EA = Embedded Artist). Along with the NXP library (lpc43xx_rtc.c & lpc43xx_rtc.h) in a Keil IDE and compiler.

I am able to initialize the RTC with a predefined time and also the clock ticks so time on the RTC increments.
I have also connected a external 3.3V battery to the VBAT pin. Voltage of this battery at the terminal is 3.02V.

But when I power down the board (i.e. remove the power totally) and start again, the RTC time resets to zero (0).

But a normal reset (i.e. by pressing the reset button without removing power) doesn't cause any problem to the RTC time (i.e time is not lost) and clocks ticks correctly after reset.

Following is the code I am using. i took this code from a topic on this forum itself.
Also the original code from NXP has same issue.

/** CCR register mask */
#define RTC_CCR_BITMASK((0x00000013))

/** Clock enable */
#define RTC_CCR_CLKEN((1<<0))

/** Clock reset */
#define RTC_CCR_CTCRST((0<<1)) // I made it zero as i thought i might be resetting the clock.

/** Calibration counter enable */
#define RTC_CCR_CCALEN((1<<4))

void RTC_Init (LPC_RTC_Type* RTCx)
{
    CHECK_PARAM(PARAM_RTCx(RTCx));

    // Configure clock to RTC
    LPC_CREG->CREG0 &= ~((1 << 3) | (1 << 2));  // Reset 32Khz oscillator
    LPC_CREG->CREG0 |= (1 << 1) | (1 << 0);     // Enable 32 kHz & 1 kHz on osc32k and release reset

RTCx->CCR = RTC_CCR_CTCRST | RTC_CCR_CCALEN;

}

void RTC_Cmd (LPC_RTC_Type* RTCx, FunctionalState NewState)
{
    CHECK_PARAM(PARAM_RTCx(RTCx));
    CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));

    if (NewState == ENABLE)
    {
        do
        {
            RTCx->CCR |= RTC_CCR_CLKEN;
        }
        while ((RTCx->CCR & RTC_CCR_CLKEN) == 0);
    }
    else
    {
        RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK;
    }
}

In the main function after intilization of other required peripherals, I am calling RTC_Init() first and then RTC_Cmd(LPC_RTC, ENABLE).

Kindly help me what is the problem because of which the RTC is losing time after power down.

Regards
Amey

Outcomes