Why was NVIC interrupt pending register not cleared by the reset switch on FRDM-K20D50M board?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why was NVIC interrupt pending register not cleared by the reset switch on FRDM-K20D50M board?

Jump to solution
2,063 Views
yasuhikokoumoto
Senior Contributor I

Hello all,

I found strange phenomenon. That is, NVIC interrupt pending registers (i.e NVIC_ISPR0 and NVIC_ICPR0) are not cleared by the reset switch on FRDM-K20D50M board.
The background is that I made a program which showed the wake up from the low power mode by RTC alarm interrupt but MCU exited from the low power mode suddenly after entering the mode for every second time. In the odd times, it succeeded. In the even times, it failed. I analyzed it and found NVIC interruts were pending even after reset. When I added NVIC interrupt clear code in the RTC setting routine, such slip phenomenon became not happened.
Can anyone answer that it is the correct behavior or the board problem?

Best regards,

Yasuhiko Koumoto.

0 Kudos
1 Solution
1,280 Views
yasuhikokoumoto
Senior Contributor I

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.

View solution in original post

0 Kudos
4 Replies
1,280 Views
yasuhikokoumoto
Senior Contributor I

Hi all (probably Mr. Kan Li),

I would like to revise my statements.
The essential of the problem is not RTC alarm interrupt but LPTMR interrupt pending of NVIC. That is, the interrupt pending bit of NVIC seems to be uncertain. Also this causes slip of the wake up from the low power mode. After reset or exit from the low power mode, the LPTMR interrupt pending bit (i.e. bit 28 of NVIC_ISPR0 and NVIC_ICPR0) may set and it causes unpredicted behavior for wake up action even if LLWU_ME[0] is '0'. Is it the specification of Kinetis MPU?

Best regards,

Yasuhiko Koumoto.

0 Kudos
1,276 Views
yasuhikokoumoto
Senior Contributor I

Hi all (probably Mr. Kan Li),


I'm sorry but I had been mistaken.
Let me revise my statement again.

By FRDM-K20D50M, bit 28 of NVIC_ISPR0 and NVIC_ICPR0 shows RTC Alarm.
LPTMR is for FRDM-KL25Z. I was confused.
After all, the problem is that RTC Alarm remains after reset asserton.
Is it correct behavior?


After reset, no interrupt is pending in NVIC_ISPR0 and NVIC_ICPR0.
However, after opening the clock gate of RTC (i.e. SIM_SCGC6[RTC]=1),
bit 28 of NVIC_ISPR0 and NVIC_ICPR0 is sometimes set to '1'.
This pending bit is not cleared even if RTC_TAP was written.
Therefore in such situation, MCU will wake up soon after exntering the low power mode.

The workaround is simple. .


1) After RTC Alarm is set, NVIC interrupt pending is to be clea to be cleared.

    SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
    RTC_CR |= RTC_CR_OSCE_MASK;
    RTC_TPR = 0;
    RTC_TSR = 0x0;
    RTC_TAR = 0x5;
    while((RTC_SR &( RTC_SR_TAF_MASK|RTC_SR_TIF_MASK))!=0);/
    NVIC_ICPR0 = 0x10000000;// This makes program happy!


I wonder whether these workarounds are necessary.
Could anyone teach me why RTC Alarm ramains after reset.

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,276 Views
yasuhikokoumoto
Senior Contributor I

Hi all,

I have found the bad part of my code.

It is that I enabled RTC alarm of NVIC_ISER0. This caused such the slip phenomenon.

In order to wake up from the low power mode, we only enable LLWU of NVIC_ISER0.

However. this would not be the reason why the RTC alarm pending remained every each time.

But I am satisfied to find the reasonable workaround (probably, was the original code was wrong?).

Best regards,

Yasuhiko Koumoto.

1,281 Views
yasuhikokoumoto
Senior Contributor I

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.

0 Kudos