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.

How to enter a TIMER0 interrupt within a TIMER1 Interrupt (Nested Interrupts)?



Hi,

I'm working with a MSP-EXP430G2 Launch pad and modifying demo code of a DLP-9070ABP RFID booster pad. I'm trying to switch the code to call the RFID "FindTag" function from an interrupt rather than from a While Loop. I've setup a TIMERA1 Interrupt to check the RFID approximately every 2 seconds.

Here is the new Interrupt Routine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma vector=TIMER1_A1_VECTOR
__interrupt void Timer_A(void) {
//Stop the counter
    TA1CTL &= ~(MC0 + MC1);
//Process the Interrupt Register
//Only handles CCR1, CCR2, and Overflow
//CCR0 Handled by different Interrupt
    switch (TA1IV) {
    case TA1IV_NONE:
        break;
    case TA1IV_TACCR1:
        Nfc_FindTag();
//      McuDelayMillisecond(1000);
//      // Add Offset to TA1CCR1
        TA1CCR1 += 3 * 2000;
//      break;
    case TA1IV_TACCR2:
        break;
    case TA1IV_6:
        break;
    case TA1IV_8:
        break;
    case TA1IV_TAIFG:
        break;
    default:
        break;
    }
    TA1CTL |= MC_1;
}

Unfortunately, I'm now in a TRAP waiting for TIMER0 to complete.

 


        g_ui8IrqFlag = 0x00;
        // Setup for the Timer
        McuCounterSet();
        // Calculate the timeout value for the timer
        COUNTER_VALUE = COUNT_1ms * ui8TxTimeout;
        // Start the Timeout
        START_COUNTER;
        while((g_ui8IrqFlag == 0x00) && (g_ui8TimeoutFlag == 0x00))    // Wait for an interrupt
        {
            // Do Nothing
        }

McuCounter sets up the following TIMER0 settings:

void
McuCounterSet(void)
{
    TACTL |= TASSEL_1 + TACLR;      // ACLK = 1.5 kHz, timer stopped

    TACCTL0 |= CCIE;                // compare interrupt enable
}

The TIMERA0 Interrupt is shown below.

//===============================================================
//    Timer A0 Interrupt Vector
//===============================================================

#pragma vector=TIMER0_A0_VECTOR
__interrupt void
Msp430g2xx3TimerAHandler(void)
{
    uint8_t ui8IrqStatus;
    ui8IrqStatus = 0x00;

    STOP_COUNTER;

    g_ui8TimeoutFlag = 0x01;

    Trf797xReadIrqStatus(&ui8IrqStatus);

    ui8IrqStatus = ui8IrqStatus & 0xF7;        // Set the parity flag to 0

    if(ui8IrqStatus == TRF797x_IRQ_STATUS_TX_COMPLETE)
    {
        g_sTrf797xStatus = TX_COMPLETE;
    }
    else if(ui8IrqStatus == TRF797x_IRQ_STATUS_IDLE)
    {
        g_sTrf797xStatus = NO_RESPONSE_RECEIVED;
    }
    else
    {
        g_sTrf797xStatus = RX_WAIT;
    }
}

I'm stuck in a While loop because TIMER0 Interrupt is not triggering. Is this because I'm already trapped in an iterrupt and can't call a 2nd Interrupt? Any suggestions would be greatly appreciated.

  • When the CPU begins executing the interrupt handler, it clears GIE to prevent nested interrupts.

    You could set GIE, but that would enable all interrupts.

    Interrupt handlers should never execute for a long time. If you need to do something long, just wake up the main loop.
  • >I'm trying to switch the code to call the RFID "FindTag" function from an interrupt rather than from a While Loop.
    Usually it is advised to move code out of interrupts as much as possible so they finish as fast as possible. You are doing opposite. Why?!

**Attention** This is a public forum