Hi all,
I have been trying to get some of the GPIO pins on my MSP430F2013 (specifically P1.2 and P1.3) to lead to an interrupt handler. I have seen another post online that does the same thing, however after copying most of that code into my project, it doesn't seem to be working for me. This is their code:
#include <msp430x54x.h>
#define Pgreen 0x08
#define Pblack 0x10
int c=0;
void main(void)
{
WDTCTL = WDTPW+WDTHOLD;
P1DIR=0x00;
P1IE=Pgreen|Pblack;
P1IES=Pgreen|Pblack;
// P1OUT=0x00;
P1IFG=0;
__bis_SR_register(GIE);
while(1)
c=0;
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if((P1IFG&Pgreen)==1) c = 1;
if ((P1IFG&Pblack)==1) c = 2;
P1IFG =0;
}
There are only a few differences here: One of the defines refers to a different pin than mine, they are using a different MSP430, and they call P1IES, which I believe is used to cause in interrupt on a high-to-low edge instead of a low-to-high one (I took that line out because I want a low-to-high edge detection).
My code does almost the exact same thing, and what I do to test it is to apply an external 3V to either one of the two pins, and check to see if the interrupt handler was called on (which would then blink the LED as a visual verification). However, it never sees to call the interrupt handler, and I am not sure why. Here is my code below:
#define EN_0 0x04
#define EN_1 0x08
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
enable_test();
}
void enable_test()
{
P1DIR = 0x00;
P1IE = EN_0 | EN_1;
//P1IES = EN_0 | EN_1; // Don't need this line, want to detect low-to-high edge.
P1IFG = 0;
__bis_SR_register(LPM0 + GIE); // Other code did not have LPM0, only had GIE (doesn't work either way).
while(1); // IS THIS WHILE LOOP NECESSARY???
}
Can anyone see what the problem is here? Did I make an incorrect change to my code or forgot to add/remove a certain line? Or am I misinterpreting how the GPIO pins and interrupt handlers work (applying a voltage to the pin). I believe that 3V is a good amount for the voltage, as when I apply the voltage to the pin with the LED, the LED lights up (also, I am applying the voltage with ground connected to the MSP430, so that is not the issue). Also, as a side note, what is the purpose of the while(1); statement?
Any help would be greatly appreciated.
Thanks,
Matt