RTC time lost after power failure on LPC4357

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

RTC time lost after power failure on LPC4357

1,635 次查看
lpcware
NXP Employee
NXP Employee
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

标签 (1)
0 项奖励
回复
4 回复数

1,265 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by michele sponchiado on Thu Jul 16 00:47:24 MST 2015
Well sorry guys, posted in the wrong thread!
[s]Hi,
I have just found that the RTCX1/2 wasn't moving because one of the two capacitors was at the wrong value.
We put 10pF measured values on both RTC capacitors, the RTC input started oscillating and the chip worked fine.
So... the strange thing is that if you enable the RTC without an external running clock, the whole chip hangs, and this was unexpected for me.

Maybe was this your issue too?
Thanks[/s]
0 项奖励
回复

1,265 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by amey_pandit on Sun Nov 02 08:57:23 MST 2014
Hi Hangdog

By the phrase "remove the power totally" means I am not removing the RTC battery I am just removing the power supply to the board. So the RTC is powered from the battery all the time. I know this looks like a silly question but it has become a show stopper.

Before this I have worked on LPC1768 RTC and it has worked well for me.

Hi Mike

I will test your steps soon and will update.

Cheers (Mine also is a pint ;) )
Amey
0 项奖励
回复

1,265 次查看
lpcware
NXP Employee
NXP Employee
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,
0 项奖励
回复

1,265 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hangdog on Fri Oct 31 07:10:22 MST 2014

Quote: amey_pandit

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).



This may sound like a very silly question, but when you say "connected an external battery", then the phrase "remove the power totally" sounds a lot like you're taking the battery away too. You're not, are you? Because that would reset the RTC.

Cheers
0 项奖励
回复