We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,
I am using MCB2300 board populated with LPC2388 for development purpose & I am facing problem in RTC.
When I disables CLKSRC bit in CCR register, RTC works well with desired values in PREINT & PREFRAC registers.
But when I enable CLKSRC bit in CCR register, RTC doesnt update.
I am posting my sample code here;
1 . RTC Configured with External Oscillator
#include <LPC23xx.H> #include <TIME.H> #include <stdarg.h> #include <stdio.h> #include <string.h> #define Fosc 12000000 // OScillator frequency - 12MHz #define Fcco 288000000 // PLL output frequency - 288MHz #define Fcclk 48000000 // CPU running frequency - 48MHz #define Fpclk (Fcclk / 2) // Peripheral frequency - 12MHz void RTC_Init(void) { PCONP |= (1 << 9); // // PCLK = 12MHz // RTC_PREINT = 0x016D; // RTC_PREFRAC = 0x1B00; RTC_CIIR = 0; RTC_CCR = 0x11; } void RTC_SetTime(struct tm *timeptr) { RTC_CCR = 0x10; RTC_SEC = timeptr->tm_sec; RTC_MIN = timeptr->tm_min; RTC_HOUR = timeptr->tm_hour; RTC_DOM = timeptr->tm_mday; RTC_DOW = timeptr->tm_wday; RTC_DOY = timeptr->tm_yday; RTC_MONTH = timeptr->tm_mon + 1; RTC_YEAR = timeptr->tm_year + 1900; RTC_CCR = 0x11; } void RTC_GetTime(struct tm *timeptr) { timeptr->tm_sec = RTC_SEC; timeptr->tm_min = RTC_MIN; timeptr->tm_hour = RTC_HOUR; timeptr->tm_mday = RTC_DOM; timeptr->tm_wday = RTC_DOW; timeptr->tm_yday = RTC_DOY; timeptr->tm_mon = RTC_MONTH - 1; timeptr->tm_year = RTC_YEAR - 1900; } void UART0_Open(unsigned long Baudrate) { unsigned long Fdiv; PINSEL0 |= 0x00000050; // Enable TxD0 and RxD0 U0LCR = 0x83; Fdiv = ( Fpclk / 16 ) / Baudrate; U0DLL = Fdiv % 256; U0DLM = Fdiv / 256; U0FDR = 0x00; U0LCR = 0x03; } unsigned short UART0_Send(unsigned char *data, unsigned short len) { unsigned short recvdlen = len; while ( len != 0 ) { while (!(U0LSR & 0x20)); U0THR = *data; data++; len--; } return recvdlen; } void DEBUG_Printf (const unsigned char *format, ...) { static unsigned char buffer[100]; va_list vArgs; va_start(vArgs, format); vsprintf((char *)buffer, (char const *)format, vArgs); va_end(vArgs); UART0_Send(buffer,strlen((const char *)buffer)); } void Delay(unsigned long Cnt) { while(Cnt--); } int main(void) { struct tm TM_CurrentTime; RTC_Init(); UART0_Open(115200); while(1) { RTC_GetTime(&TM_CurrentTime); DEBUG_Printf("\n\rTime : %s",asctime(&TM_CurrentTime)); Delay(0xffff); } }
2 . RTC configured with PCLK
void RTC_Init(void) { PCONP |= (1 << 9); // PCLK = 12MHz RTC_PREINT = 0x016D; RTC_PREFRAC = 0x1B00; RTC_CIIR = 0; RTC_CCR = 0x01; } void RTC_SetTime(struct tm *timeptr) { RTC_CCR = 0x00; RTC_SEC = timeptr->tm_sec; RTC_MIN = timeptr->tm_min; RTC_HOUR = timeptr->tm_hour; RTC_DOM = timeptr->tm_mday; RTC_DOW = timeptr->tm_wday; RTC_DOY = timeptr->tm_yday; RTC_MONTH = timeptr->tm_mon + 1; RTC_YEAR = timeptr->tm_year + 1900; RTC_CCR = 0x01; }
please suggest me if I am missing any configuration..
Xafar