Folks,
we are using a K20N512VLL100 (Datecode 1N30D) and are trying to tame the RTC and its interrupts.
We want to use an Alarm IRQ (periodically generated every second) to have a substitute for the seconds interrupt (which we think is not implemented, because we did not find any "dedicated interrupt vector" as mentioned in the manual).
Here is our (rather simple) init code for the RTC:
...
/*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 RTC interrupt in NCVIC */
NVICICPR2 |= 0x4; //Clear RTC pending interrupts in NVIC
NVICISER2 |= 0x4; //Enable RTC interrupts in NVIC
/*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++);
RTC_CCR = 0x00;
RTC_TSR = 0; // Initialize Time ....later only if VBat was lost
RTC_TAR = RTC_TSR + 10; // First RTC alarm should come up in 10 seconds
/* Enable the counter */
RTC_SR |= RTC_SR_TCE_MASK;
...
Now we expect all is done....here is our RTC-ISR:
...
if ((RTC_SR & RTC_SR_TIF_MASK)== 0x01)
{ RTC_SR &= 0x07; //clear TCE, or RTC_TSR can not be written
RTC_TSR = 0x00000000; //clear TIF
}
else if ((RTC_SR & RTC_SR_TOF_MASK) == 0x02)
{ RTC_SR &= 0x07; //clear TCE, or RTC_TSR can not be written
RTC_TSR = 0x00000000; //clear TOF
}
else if ((RTC_SR & RTC_SR_TAF_MASK) == 0x04)
{ RTC_TAR += 1; // Write new alarm value, to generate an alarm every second add 1
}
Now, we get a strange behavior:
After this init we got a interrupt with Bit 0 (TIF) of RTC_SR set. This is handled by the ISR properly. But never we get an Alarm Interrupt TAF (RTC_SR Bit 2) set. But the Alarm flag TAF is set, we checked this by polling it in our main loop.
When we disable all RTC interrupt sources in RTC_IER, of course no ISR call is done. But independent which interrupt we enable (even if we only enable only the alarm interrupt) we always get the TIF interrupt, but never an TAF alarm interrupt...
What is our mistake ?
Thanks, Ulf