Hi Bill,
It's strange that, I have received your updated information in the email, but the post I can't see it.
This your updated information:
================================================================================
Hi Kerry,
Thanks for your efforts on this issue.
The headche problem we had that RTC module could not work as expected.
You could see following picture on the real device.
https://community.nxp.com/servlet/JiveServlet/downloadImage/2-975375-207887/RTCErrorWithDebugInfo.PN...
We made following work around.
"
Chip_Clock_RTCEnable();
for (waitMS = 0; waitMS < 2000; waitMS++)
{
LPC_RTC->CCR = value | (1uL << 4); // Disable calibration
if ((LPC_RTC->CCR & 0x1FuL) == (value | (1uL << 4)))
{
LPC_RTC->CALIBRATION = 0; // Disable calibration
return(true); // Leave if it is done
}
_BusyWaitMicroSeconds(1000uL); // Wait 1 millisecond
}
"
From the testing, the leave time after RTC ready is around 1700ms.
But it's ugly that we have to disable calibration always in the loop.
We tested that move this disable calibration after delay 3.2 seconds, RTC could not work either.
It's appreciated that NXP could help us confirm the work around would not cause other problem.
========================================================================================
Actually, I have test the official RTC code, even the first time atimer is not precise, but the RTC still works OK.
It seems on your side, your RTC problem is caused the 2S time is not enough which is caused by the atimer.
Another suggestion, I think you still can refer to the lpcopen code
void Chip_RTC_Init(LPC_RTC_T *pRTC)
{
// Chip_Clock_RTCEnable();
/* 2-Second delay after enabling RTC clock */
// LPC_ATIMER->DOWNCOUNTER = 2048; //just add another 2S delay here
// 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;
}
From my test, I find the first time 2S is not precise, because the altimer is running after reset, but the second 2S is precise.
So, I think, you also can add two altimer code, just make sure, before the RTC is enabled, there more than 2S.
Chip_ATIMER_Init(LPC_ATIMER, PresetCount);
while (LPC_ATIMER->DOWNCOUNTER);
You can try it on your side, whether it works ok on your side?
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------