Hi all,
I have found the reason why RTC alarm wake-up from the low power mode fails at every second time.
First of all, we should know NVIC RTC alarm interrupt vector was used for all RTC related interrupts except RTC time seconds interrupt.
The reason is the following.
(Power On Reset: 1st time)
RTC_SR[TIF] is set and NVIC_ISPR[RTC alarm] is also set.
This makes Kinetis MCU exited soon from the low power mode (i.e. FAIL).
In this case RTC_TSR count did not reach to RTC_TAR value.
(2nd, 4th, 6th,... time)
RTC alarm interrupt did not yet occur, and RTC alarm interrupt occurs after entering the low power mode (i,e, SECCEED).
(3rd, 5th, 7th,... time)
Because at the even time RTC alarm interrupt occurred, RTC_SR[TAF] is set.
Also NVIC_ISPR[RTC alarm] is already set. This may be the same situation as the Power On Reset (i.e. FAIL).
If wake-up performed wrongly, NVIC_ISPR[RTC alarm] seemedd to be automatically cleared.
The workarounds are as follows. We can choose one of them.
(1) NVIC_ISPR[RTC alarm] should be cleared after RTC[AIF] was cleared by writing to RTC_TAR.
(2) NVIC_ISER[RTC alarm] should not be enabled when RTC alarm was used for the waking up from the low power mode.
Best regards,
Yasuhiko Koumoto.