This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: Clearing timer TATOINT interrupt flag requires extra clock cycles to take effect?

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: LM3S1968

I'm developing some example code for a class and came across something I didn't expect.  

I ported some timer interrupt code in C from an LM3S1968 which accesses the GPTM registers directly, not through the PDL. The last line in the Timer2A Time-out interrupt handler does this:

  TIMER2_ICR_R = TIMER_ICR_TATOCINT;

What I discovered is the interrupt fires once, but then immediately fires again after exiting the handler.  Setting a breakpoint at the first instruction of the handler shows the TIMER_MIS and TIMER_RIS both with 0x01 on the first interrupt, and both with 0x0 on the second.  If I insert a few instructions after the write to the ICR register, no second interrupt occurs.

I checked the GPTM, NVIC and Exception Model sections of the datasheet but didn't see any warning about extra clock cycles being needed after clearing flags.

Am I missing something elsewhere?

  • Hi Ken,
    I think what happens is that it takes some cycles to complete the write-clear operation. The write-to-clear the bit did not really complete before you exit the ISR. So immediately after you exit the ISR the interrupt is still pending since the flag did not clear yet. This is why it will re-enter the ISR but the second time the flag is clear. By the 2nd time the ISR is entered the flag is already cleared. There are two options I can suggest. First, clear the flag immediately when you enter the ISR, meaning to move the TIMER2_ICR_R = TIMER_ICR_TATOCINT as the first line of the ISR instead of the last line. The second option is to read the TIMER2_ICR_R register after you clear the bit. The read will guarantee the flag is really cleared before you exit the ISR.
  • Hi, Charles:

    Yes, I think that's what is happen also. I was aware of similar issues with turning on the clocks in the RCGC registers on the Stellaris MCU, but discovered that doesn't seem to be the case anymore on the Tiva.

    Ken