Hello, I'm having problems with RTC in LPC1768. The RTC is running, but is advancing approx 5 seconds per hour. The electrical circuit is good, with a 20ppm crystal tolerance, and 12,5pf capacitors of load. Tha VBAT is conected in CR1220 lithium battery. I have reviewed the source code and is OK. Below is my code:
void InitRTC(void) { LPC_RTC->CCR = ( !CLKEN | CTCRST ); LPC_RTC->CCR &= ~CTCRST; return; } /***************************/ void StartRTC(void){ LPC_RTC->CCR |= ( CLKEN ); return; } /***************************/ int main (void){ char temp[36]; InitRTC(); StartRTC(); while(1){ sprintf ((char *)temp,"%2.2d/%2.2d/%.2d %2.2d:%2.2d",LPC_RTC->DOM,LPC_RTC->MONTH,LPC_RTC->YEAR,LPC_RTC->HOUR,LPC_RTC->MIN); lcd_gotoxy(1,0); lcd_print(temp); } return 0; }
The RTC is running correctly without the battery, with main power connected in VBAT. But yet the RTC is running advancing. I can't use the calibration of application note AN10849. I have 100 identical hardwares, and they are with different accurate. I think that this variation is very high for be simply a low accuracy of LPC. There must be some other problem.
Does anyone know what might be happening? Thanks
lpc17xx.cmsis.driver.library.zip
/********************************************************************//** * @brief Initializes the RTC peripheral. * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @return None *********************************************************************/ void RTC_Init (LPC_RTC_TypeDef *RTCx) { CHECK_PARAM(PARAM_RTCx(RTCx)); /* Set up clock and power for RTC module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE); // Clear all register to be default RTCx->ILR = 0x00; RTCx->CCR = 0x00; RTCx->CIIR = 0x00; RTCx->AMR = 0xFF; RTCx->CALIBRATION = 0x00; } /*********************************************************************//** * @brief Enable/Disable calibration counter in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] NewState New State of this function, should be: * - ENABLE: The calibration counter is enabled and counting * - DISABLE: The calibration counter is disabled and reset to zero * @return None **********************************************************************/ void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState) { CHECK_PARAM(PARAM_RTCx(RTCx)); CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState)); if (NewState == ENABLE) { RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK; } else { RTCx->CCR |= RTC_CCR_CCALEN; } }
/*-------------------------MAIN FUNCTION------------------------------*/ /*********************************************************************//** * @brief c_entry: Main RTC program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { [DELETED] /* Enable rtc (starts increase the tick counter and second counter register) */ RTC_ResetClockTickCounter(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); RTC_CalibCounterCmd(LPC_RTC, DISABLE); [DELETED]