Can someone please help me in configuring the RTC timer on K60 to be able to generate an interrupt after 1 sec.The following is the code snippet that i used to configure the RTC.However,on calling "enable_irq(66)" instruction,the control is switched to ISR routine immediately without even executing further instructions that are supposed to get executed.Even on using this instruction "enable_irq(66)" at the end of the function at the end of the function "void rsi_mcu_rtc_init(uint32 time_in_seconds)",the control switches to ISR immediately. which i measure it to about 500ms.
Here i am measuring time on an oscilloscope by toggling a GPIO pin using "enable_test_gpio()" and "disable_test_gpio()" which wont show an expected time of 1sec.
So,what i expect is that only after enabling the counter should the timer start ticking and after 1 sec only the control should switch to the ISR routine.
Appreciate your help in helping me solve this issue.
Code:
uint8 rsi_rtc_interrupt_flag = 0;
void rsi_mcu_rtc_init(uint32 time_in_seconds)
{
int i;
/*enable the clock to SRTC module register space*/
SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
/*Only VBAT_POR has an effect on the SRTC, RESET to the part does not, so you must manually reset the SRTC to make sure everything is in a known state*/
/*clear the software reset bit*/
RTC_CR = RTC_CR_SWR_MASK;
RTC_CR &= ~RTC_CR_SWR_MASK;
/*Enable the interrupt*/
enable_irq(66);
/*Enable the oscillator*/
RTC_CR |= RTC_CR_OSCE_MASK;
/*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/
for(i=0;i<0x600000;i++);
/*Set time compensation parameters*/
//RTC_TCR = RTC_TCR_CIR(0) | RTC_TCR_TCR(0);
/*Configure the timer seconds and alarm registers*/
RTC_TSR = time_in_seconds;
//RTC_TPR = 0x8008;
RTC_TAR = 0x00;
enable_test_gpio(); // Drive the GPIO pin HIGH (to measure time)
/*Enable the counter*/
RTC_SR |= RTC_SR_TCE_MASK;
while(rsi_rtc_interrupt_flag == 0);
disable_test_gpio(); // Drive the GPIO pin LOW (to measure time)
}
void rsi_rtctimer_ISR(void)
{
rsi_rtc_interrupt_flag = 1;
RTC_IER = (0<<RTC_IER_TOIE_SHIFT)& RTC_IER_TOIE_MASK;
printf("ISR\n");
}