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.

MSP430F2011: basic question on P1IV

Part Number: MSP430F2011

I have the following ISR for port 1.....I am having issues with the switch.  If I come into the ISR and only BIT2, BIT4 or BIT5 are set the switch works but if I come into the ISR where BIT4 and BIT5 are both set the switch jumps right to default and neither gets executed.  This leads me to wonder how is it possible to have a switch in the ISR at all as you would have to have 128 separate case statements one for each iteration of BITs 0 -7 and all combinations.  How does p1 vector handle for example (PI1FG = 00110000 ) given the following below?

#pragma vector=PORT1_VECTOR
__interrupt void inputs(void)
{
    switch( P1IFG )
    {
    case 4:
        //trigger 1
        P1IE &= ~BIT2;
        P1IFG &= ~BIT2;
        ISR.trig1 = true;
        break;
    case 16:
        //trigger 2
        P1IE &= ~BIT4;
        P1IFG &= ~BIT4;
        ISR.trig2 = true;
        break;
    case 32:
        //debug mode enable debounce
        P1IE &= ~BIT5;
        P1IES ^= BIT5;
        P1IFG &= ~BIT5;
        CCR0 = (TAR + DEBOUNCE); //~~50ms
        CCTL0 &= ~CCIFG;
        CCTL0 |= CCIE;
        break;
    default:
        break;
    }
    LPM3_EXIT;
}

  • On hardware which has an IV register you can use a case statement like that since it returns one and only one value at a time. When dealing with the IFG register you cannot use a case like that. It is much easier and more efficient to use:

    if(P1IFG & BIT4) 
      {}
    if(P1IFG & BIT5)
      {}

  • Thanks David....

    That is the path I found also....HOWEVER....I found that you must use 

    else if 

    If you just use if in both cases when you come into the ISR it will evaluate both if statements independent of the enable

  • Using "else if" only fixes the problem of an IFG flag being set when the IE flag isn't if the order of tests matches your IE settings. If set interrupt flags with disabled IE bits is a problem, you will have to include the IE register in the "if" statement. "if(P1IE & P1IFG & BIT5)"

**Attention** This is a public forum