AnsweredAssumed Answered

lpcopen_3_02 code not according to LPC1857 UM10430 v3.0

Question asked by Bill Sheng on Jan 4, 2018
Latest reply on Jan 8, 2018 by Bill Sheng

On LPC1857 UM10430 v3.0 36.2 there have following remarks:

"

Remark: After initializing the 32 kHz oscillator, wait for 2 sec before writing to the RTC
registers (see Section 36.7.1).
Remark: Only write to the RTC registers when the 32 kHz oscillator is running. Repeated
writes to the RTC registers without the 32 kHz clock can stall the CPU. To confirm that the
32 kHz clock is running, read the Alarm timer counter register (DOWNCOUNTER, see
Table 787), which counts down from a preset value using the 1024 Hz clock signal derived
from the 32 kHz oscillator.

"

On LPC1857 UM10430 v3.0 34.2 there have following remark:

"

Remark: Only write to the Alarm timer registers when the 32 kHz oscillator is running.
Repeated writes to the Alarm timer registers without the 32 kHz clock can stall the CPU.
To confirm that the 32 kHz clock is running, read the Alarm timer counter register
(DOWNCOUNTER, see Table 787), which counts down from a preset value using the
1024 Hz clock signal derived from the 32 kHz oscillator.

"

The code in NXP\lpcopen_3_02_keil_iar_mcb1857\LPC43xx_18xx\chip_43xx_18xx\src\rtc_18xx_43xx.c  

/* Initialize the RTC peripheral */
void Chip_RTC_Init(LPC_RTC_T *pRTC)
{
Chip_Clock_RTCEnable();

/* 2-Second delay after enabling RTC clock */
LPC_ATIMER->DOWNCOUNTER = 2048;
while (LPC_ATIMER->DOWNCOUNTER);

/* Disable RTC */
Chip_RTC_Enable(pRTC, DISABLE);

/* Disable Calibration */
Chip_RTC_CalibCounterCmd(pRTC, DISABLE);

/* Reset RTC Clock */
Chip_RTC_ResetClockTickCounter(pRTC);

/* Clear counter increment and alarm interrupt */
pRTC->ILR = RTC_IRL_RTCCIF | RTC_IRL_RTCALF;
while (pRTC->ILR != 0) {}

/* Clear all register to be default */
pRTC->CIIR = 0x00;
pRTC->AMR = 0xFF;
pRTC->CALIBRATION = 0x00;
}

 

The code in Red color part, actually could not work as expected.

Following are the debug message for the timing:

"

(14:26:55.35) RTC: Start check downcounter with 2048
(14:26:55.41) RTC: End to check downcounter

"

It's only 60ms, not 2 second as expectation.

 

So the driver could not work on some MCU which has potencial internal RTC issue.

What's the correct code to cover this internal RTC remarks from user guide?

Outcomes