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?
Hi Bill,
Thank you for your interest in NXP LPC product, I would like to provide service for you.
I think this problem is related to the Alarm timer. I already reproduced your problem on my side, it seems the first time after reset, the alarm timer is not precise, because the DOWNCOUNTER already works, the write has no influence.
I test it with the following code, it can get 2S now:
The above code will get two times 2Seconds.
We can check the LED2 pin, this is the oscilloscope wave about the LED2 pin in MCB1857:
This is the printf data after just reset:
Begin1 begin1 Downcounter=6a3 ; PresetCount=800; enable=0
Downcounter=69e ; PresetCount=800; enable=0
Downcounter=0 ; PresetCount=0; enable=0
Downcounter=0 ; PresetCount=800; enable=0
End1begin2 Downcounter=7fd ; PresetCount=800; enable=0
Downcounter=7f9 ; PresetCount=800; enable=0
Downcounter=0 ; PresetCount=800; enable=0
End2 ========================================
but, even I can get the 2S now, I think there still have problems with the alarm timer, I am still working on it, and I need to check it with our according department.
After I get the updated information, I will let you know.
Please wait patiently.
You also can do the alarm timer test on your side, any updated information, please kindly let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------