I am trying to use the RTC interrupts to count seconds. However it only runs in debug mode and also in this increments one second in 1 and 1/2 minutes. Do I have to set any flags before using the RTC? I am trying to to the counting using the internal RTC clock
This is how I initialized it
PCONP |= 0x200; // Enable power for RTC RTC_CCR = 0x12 //Reset clock and select RTC clock from 32KHz oscillator RTC_ILR = 0x1; //Clear the Interrupt Location Register RTC_HOUR = 0x2; RTC_MIN = 0x1; RTC_SEC = 0x5; RTC_CIIR =0x1; //enable seconds counter interrupt RTC_CCR = 0x11; // start RTC VICIntSelect = 0x000; VICIntEnable = 0x2000; VICVectCntl13 = 0x2D; VICVectAddr13 = (unsigned int)read_rtc;
The interrupt function was written as follow
void read_rtc() __irq { int hour = 0; int min = 0; int sec; hour = (RTC_CTIME0 & MASKHOUR)>>16; min = (RTC_CTIME0 & MASKMIN)>>8; sec = RTC_CTIME0 & MASKSEC; if (sec == 0x6) {FIO2SET = 0xFF;} RTC_ILR= 0x1; VICVectAddr = 0x0; }
Why do you enable the interrupt before you set the interrupt handler?