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.
I'm trying to use the RTC on my MCB2300 with Keil IDE. The NXP example is only using the internal clock. My initialization seems to be ok, according to the lpc23xx manual. But I'm facing 2 issues. First, my code is running only in debug mode. When not in debug mode, it seems that interrupt is never fired. In debug mode (even without breakpoint) interrupt behaviour is great but timing is really slow (1seconde every 4 or 5sec). I'm powering RTC with PCONP register before initialization, then I set CCR register to use external oscillator. Then I set my interrupt and I enable my RTC. I don't understand what I'm missing here. Thanks for any help !
(I don't know much about this.)
Does your RTCInit() look like the below?
void RTCInit( void ) { alarm_on = 0; /*--- Initialize registers ---*/ RTC_AMR = 0; RTC_CIIR = 0; RTC_CCR = 0; RTC_PREINT = PREINT_RTC; RTC_PREFRAC = PREFRAC_RTC; return; }
If it does, please check the "RTC_CIIR = 0;" (Counter Increment Interrupt Register)
Thanks for answering. I tryed a lot of different initialization but I took care about the RTC_CIIR register. Actually, here is my RTCinit() :
void RTCInit( void ) { alarm_on = 0; PCONP |= (1<<9); /* must be powered during configuration*/ /*--- Initialize registers ---*/ RTC_ILR = ILR_RTCALF | ILR_RTCCIF; /* Disable 32'768 interrupt */ RTC_AMR = 0; /* alarm mask register */ RTC_CIIR = 0; /* counter increment interrupt */ RTC_CCR |= CCR_CLKSRC; /* CCR_CLKSRC = 0x10 : external oscillator */ /* //RTC_PREINT = PREINT_RTC; // 0 //RTC_PREFRAC = PREFRAC_RTC; // 0 */ RTC_CIIR |= 1; /* sec interrupt */ return; }
Any idea ? Thanks again.
Maybe, add the below code to your RTCInit()
RTC_CISS = 0;
(Counter Increment Select Mask Register)
What does your RTCHandler() do?
You said that your code doesn't work in normal mode. "When not in debug mode, it seems that interrupt is never fired."
If the "Counter Increment Interrupt" is fired, what will you see?
Could you please confirm that, in debug mode, you really get a "Counter Increment Interrupt" (RTCCIF)? not an "alarm registers generated interrupt" (RTCALF), neither a "Counter Increment Sub-Seconds interrupt" (RTSSF).
Well, I finally find my problem : it comes from the hardware. The crystal on my MCB2300 seems to be broken. I should have check it before but the behaviour in debug mode had confused me (crazy behaviour that made a clock without external oscillator)! Moreover, I used to trust keil's hardware. Anyway, it's working now and I understand what was going on, so that's the point ! Thanks again John.
" ... behaviour in debug mode had confused me (crazy behaviour that made a clock without external oscillator)!"
Are you sure it was just debug mode, and not the Simulator...?
No, I've just checked again. I used ULINK ARM Debugger... It seems that the RTC was using the main clock and not the external oscillator. It's so weird but I've lost enough time to investigate it.
Dear Aurelien Shyam here, Do u rememember? that u send me code during my SPI communication.
here I am sending Whole (RTC initalation ,RTC_ISR) RTC code which is I implemented in my project.
void InitRTC(void) { // Enable power for RTC PCONP |= 0x200; // CTC reset and select RTC clock from 32 Khz.oscillator RTC_CCR = 0x12; // Clear RTC interrupt register RTC_ILR = 0xFF; // Dasable all the alrams. RTC_AMR = 0xFF; // Enable only second count interrupt. RTC_CIIR = 0x01; // minute // Disable all subsecond interrupts. RTC_CISS = 0; // Enable RTC RTC_CCR = 0x11; return; } void Set_RTC(RTC Time) { RTC_CCR &= 0xFE; RTC_SEC = Time.RTC_Sec; // Minute value [0-59] RTC_MIN = Time.RTC_Min; // Hour value [0-23] RTC_HOUR = Time.RTC_Hour; // Day of week value [0-6] RTC_DOW = Time.RTC_Wday; // Day of month value [1-31] RTC_DOM = Time.RTC_Mday; // Month value [1-12] RTC_MONTH = Time.RTC_Mon; // Year value RTC_YEAR = Time.RTC_Year; // Day of year value [1-365] RTC_DOY = Time.RTC_Yday; RTC_CCR |= 0x01; return; } RTC Read_RTC(void) { RTC Local_time; Local_time.RTC_Sec = ((RTC_CTIME0 & 0x0000003F)>>0); rtcdata = ((RTC_CTIME0 & 0x0000003F)>>0); // Minute value [0-59] Local_time.RTC_Min = ((RTC_CTIME0 & 0x00003F00)>>8); // Hour value [0-23] Local_time.RTC_Hour = ((RTC_CTIME0 & 0x001F0000)>>16); // Day of week value [0-6] Local_time.RTC_Wday = ((RTC_CTIME0 & 0x07000000)>>24) ; // Day of month value [1-31] Local_time.RTC_Mday = ((RTC_CTIME1 & 0x0000001F)>>0); // Month value [1-12] Local_time.RTC_Mon = ((RTC_CTIME1 & 0x0000FF00)>>8); // Year value Local_time.RTC_Year = ((RTC_CTIME1 & 0x0FFF0000)>>16); // Day of year value [1-365] Local_time.RTC_Yday = RTC_DOY; RTC_CCR |= 0x01; return (Local_time); } void RTC_ISR (void) __irq { if (RTC_ILR &=0x00000001) { Count++; } RTC_ILR = 0x00000001; VICVectAddr = 0x00000000; }
if any problem give me meg.
Thanks Shyam T.
Thanks a lot Shyam but as I have said before, it was an hardware issue. My code is working. But thanks again, I really appreciate it.