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.

MSP430F5529: MSP430F5529 GPIO Interupt not working :-(

Part Number: MSP430F5529

Hi All,

newbie here.

I have been playing around with some code along with the MSP430F5529 launch pad. I am currently trying to get my head around interupts. Please could someone explain where i am going wrong with my (simple) code ?

When i use break points, It would seem that the program is hitting the interrupt, but the while loop is not acknowledging the flag ==1 ?

#include "msp430.h"
volatile int flag = 0;

void main(void)
{
P1REN = 0x02; //enables pull up resistor on switch p1.1  
P1DIR = 0x01; //set led P1.0 as output and switch p1.1 as input
P1OUT = 0x02; //LED off by defalt, SW pulled high

P1IES |= 0x02; //interupt on sw high->low (1)
P1IFG &= ~0x00; //clear flag
P1IE |= 0x02; //enables interupts on pin 1.1

__enable_interrupt();
while(1)
    {
      if (flag == 1)
      {
        P1OUT ^= 0x01; //LED on   
        flag = 0;
      }
      else
      {
        //do nothing
      }  
    }
}
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR(void)
{
  flag = 1;
  P1IFG &= ~0x00; //clear flag
}

 

Thanks in advance,

  • Your interrupt flag will not be cleared by using "&= ~0x00" - use "&= ~0x02" instead. And you have to care about contact debouncing, otherwise you might get multiple interrupts for a single press.
  • Hi Dennis,

    Thanks very much, this has sorted my problem.

    De-bouncing was going to be my next question, as my LED is flickering on and off with each press.  I understand how i would implement this via hardware, but how would i best implement this in software ?

    Thanks again,

  • A basic question on your code sample :   Did you turn off Watchdog immediately upon starting main()  ?

  • Good point.. no I didn't. Could this be causing my issues ??
  • An unitiailized Watchdog is certain to cause trouble. It will definitely trigger an 'NMI' type INT - I can't recall at the moment where CCS will default vector this to, but you can find it via 'suspend' in CCS debug - it'll probably reveal the code just spinning on one location.
  • Otto is right - the watchdog will restart your system over and over again if you do not feed or stop him. To stop the watchdog, just place this line at the top in your main():

    WDTCTL = (WDTPW | WDTHOLD);
  • richard finch said:
    but how would i best implement this in software

    There are multiple ways to do this. In my opinion, an interrupt for a button is overkill - I prefer a timer, kicking in every 10ms to see if the button state has changed. 10ms is enough time for debouncing. But using an interrupt is OK, of course. You could also start a timer inside the button interrupt and inside the timer interrupt you determine if the button press still exists and if so, signal a valid button press via a flag to the main. But if you do not have hardware debouncing you definitely need some sort of software debouncing, otherwise you will have multiple detected button presses for a single human press.

**Attention** This is a public forum