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.

ISR not triggering for Iiterrupt example for MSP430F5529



I loaded an example for the 5529 that blinks an LED every time a pin interrupt is detected. I modified the code to use a user button instead of an empty GPIO (P1.4) pin for the dev board (P1.1). Before I commented out the interrupt enable and disable in the main and ISR respectively, the program would, with low consistency, operate correctly. I removed both lines and the program executes perfectly. Could someone explain how this works? Thanks.


#include <msp430.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= BIT0; // Set P1.0 to output direction P1OUT &= ~BIT0; P1REN |= BIT1; // Enable P1.4 internal resistance P1OUT |= BIT1; // Set P1.4 as pull-Up resistance P1IES &= ~BIT1; // P1.4 Lo/Hi edge P1IFG &= ~BIT1; // P1.4 IFG cleared P1IE |= BIT1; // P1.4 interrupt enabled while(1) { __bis_SR_register(LPM0_bits + GIE); // Enter LPM4 w/interrupt __no_operation(); // For debugger P1OUT ^= BIT0; // P1.0 = toggle // P1IES ^= BIT1; // Toggle between H-L and L-H transition triggers // P1IE |= BIT1; // Enable port interrupt } } // Port 1 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(PORT1_VECTOR))) Port_1 (void) #else #error Compiler not supported! #endif { P1IFG &= ~BIT1; // Clear P1.4 IFG // P1IE &= ~ BIT1; // Clear P1.4 IE __bic_SR_register_on_exit(LPM0_bits); // Exit LPM4 }

  • I apologize for the first post, I included my paragraph inside the code snippet.

    I loaded an example for the 5529 that blinks an LED every time a pin interrupt is detected. I modified the code to use a user button instead of an empty GPIO (P1.4) pin for the dev board (P1.1). Before I commented out the interrupt enable and disable in the main and ISR respectively, the program would, with low consistency, operate correctly. I removed both lines and the program executes perfectly. Could someone explain how this works? Thanks.

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      P1DIR |= BIT0;                            // Set P1.0 to output direction
      P1OUT &= ~BIT0;
      P1REN |= BIT1;                            // Enable P1.4 internal resistance
      P1OUT |= BIT1;                            // Set P1.4 as pull-Up resistance
      P1IES &= ~BIT1;                           // P1.4 Lo/Hi edge
      P1IFG &= ~BIT1;                           // P1.4 IFG cleared
      P1IE |= BIT1;                             // P1.4 interrupt enabled
    
      while(1)
      {
        __bis_SR_register(LPM0_bits + GIE);     // Enter LPM4 w/interrupt
        __no_operation();						// For debugger
        P1OUT ^= BIT0;                          // P1.0 = toggle
    //    P1IES ^= BIT1;                          // Toggle between H-L and L-H transition triggers
    //    P1IE |= BIT1;                           // Enable port interrupt
      }
    }
    
    // Port 1 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(PORT1_VECTOR))) Port_1 (void)
    #else
    #error Compiler not supported!
    #endif
    {
      P1IFG &= ~BIT1;                         // Clear P1.4 IFG
    //  P1IE &= ~ BIT1;                         // Clear P1.4 IE
      __bic_SR_register_on_exit(LPM0_bits);   // Exit LPM4
    }
  • Hi Sheldon,

    Couple of things here:

    First, for the switch input your comments say P1.4, but your code is written for P1.1. I'm assuming this is just because the comments have not been updated.

    Second, you are likely running into the bouncing on the switch. This is causing your interrupt to fire multiple times, which causes the output pin to toggle multiple times. You should debounce the switch in hardware (with debounce logic), or in software (introducing a delay in the ISR that allows enough time for the switch to finish bouncing). Whichever method you chose, please note that if you are using a momentary switch (it reverts to default state when you release the switch), when you release the switch and it goes back to defualt, it will bounce again, which will cause your interrupt to fire again.

    Mike

**Attention** This is a public forum