This is the code to enable RTC, set time, and read time from it. I use the LPC-Link2 as the debug probe and connect to another LPC-Link2 board. The program was unable to run through the do-while loop after the LPC_RTC->CCR |= RTC_CCR_CTCRST statement. Then it crashed eventually. What is the problem? Please help!
Chip_Clock_RTCEnable();
delay(3000);
/* Disable RTC */
LPC_RTC->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK;
/* Disable Calibration */
LPC_RTC->CCR |= RTC_CCR_CCALEN;
/* Reset RTC Clock */
LPC_RTC->CCR |= RTC_CCR_CTCRST;
do {
} while ((LPC_RTC->CCR & RTC_CCR_CTCRST) != RTC_CCR_CTCRST);
/* Finish resetting RTC clock */
LPC_RTC->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK;
do {
} while (LPC_RTC->CCR & RTC_CCR_CTCRST);
/* Clear counter increment and alarm interrupt */
LPC_RTC->ILR = RTC_IRL_RTCCIF | RTC_IRL_RTCALF;
while (LPC_RTC->ILR != 0) {}
/* Clear all register to be default */
LPC_RTC->CIIR = 0x00;
LPC_RTC->AMR = 0xFF;
LPC_RTC->CALIBRATION = 0x00;
// Set time
Chip_RTC_SetFullTime(LPC_RTC, &FullTime);
// Enable RTC time counters
Chip_RTC_Enable(LPC_RTC, ENABLE);
// Read time
Chip_RTC_GetFullTime(LPC_RTC, &FullTime);