1

I had set MSP430F5418 P2.5 for high to low transition. But I am getting interrupts for both low-to-high and high-to-low transitions. Please my code snippet below.


    P2OUT |= BIT5   /* Enable P2.5 internal resistances */
    P2REN |= BIT5   /* Set up P2.5 as pull-Up resistances */

    P2IES |= BIT5;    
    P2IE  |= BIT5;    
    P2IFG &= ~BIT5;   /* P2.5 IFG cleared */


#pragma vector=PORT2_VECTOR
__interrupt void port2_interrupt (void)
{
    switch (P2IV)
    {
        case 0x0CU:
        {
            /* Do something here */
            P2IFG &= ~BIT5;
            break;
        }
        default:
        {
            /* No Action */
            break;
        }
    }
}
Ammamon
  • 467
  • 1
  • 10
  • 18
  • 2
    Is the signal debounced properly? Don't wire it straight to a mechanical switch. – Hans Passant Jul 02 '11 at 14:49
  • without using texas msp, I'd say debounce too. If you don't disable the interrupts on the ISR (I don't know if it's done automatically with that code, but usually it's something that the programmer need to do), just debouncing won't solve. – rnunes Jul 03 '11 at 02:11
  • Interrupt is automatically disabled in my MSP430 device when interrupt routine is entered. – Ammamon Jul 04 '11 at 12:24

2 Answers2

0

Hans, I am not using a switch to assert the pin. It is actually done by another processor. I got a reply In TI (Texas instruments) forum that there could be a hidden high-to-low signal within a low-to-high transition and vice versa.

So, I modified my code as follows and it worked fine.

...

 P2OUT |= BIT5 ;   /* Enable P2.5 internal resistance */
 P2REN |= BIT5;    /* Set up P2.5  as pull-up resistance */

 P2IES |= BIT5;    /* Sets P2IFG for high to low transition */
 P2IE  |= BIT5;    /* P2.5 interrupt enabled */
 P2IFG &= ~BIT5;   /* P2.5 IFG cleared */
...

#pragma vector=PORT2_VECTOR
__interrupt void port2_isr (void)
{
    switch (P2IV)
    {
        case 0x0CU:
        {
            TA1CCTL0 &= ~CCIE;
            TA1CCR0 = 0U;
            TA1CCTL0 |= CCIE;
            TA1CCTL0 &= ~CCIFG;
            TA1CCR0 = TA1R + 15U;
            P2IFG &= ~BIT5;
            break;
        }
        ...
        ...
    }
}

#pragma vector = TIMER1_A0_VECTOR    /*  Timer1_A3 CC0 */
static __interrupt void _timer1_ao_isr (void)
{
    TA1CCTL0 &= ~CCIE;
    if ((P2IN & BIT5) == 0U)
    {
       // Got a valid high-to-low assert here!!!
    }
}

Ammamon
  • 467
  • 1
  • 10
  • 18
0

Not actually an answer, just a suggestion, rename your variables to something more meaningful, two months from now you won't remember that BIT5 is the pin that you check for a high-to-low transition. You can use a define to rename BIT5 to say, HIGH_TO_LOW_PIN. You can do the same thing with the timer setup, refactor it to something more meaningful.