Part Number: MSP430FR5994
Tool/software: Code Composer Studio
Hi,
I currently have a program that uses the onboard buttons as interrupts to toggle the LEDs, but for some reason, the interrupt function is called before the buttons are ever pressed.
I used the command P5IFG &= ~(BIT5 + BIT6); to clear the interrupt flags before the IO pins were unlocked, so I am unsure of why this is happening. Can someone please explain why this is happening?
My program is shown here:
#include <msp430.h>
volatile int flag1 = 0;
volatile int flag2 = 0;
/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
//Configure Unused Pins to the lowest power State (Output direction, tied low)
P1OUT = 0;
P1DIR = 0xFF;
P2OUT = 0;
P2DIR = 0xFF;
P3OUT = 0;
P3DIR = 0xFF;
P4OUT = 0;
P4DIR = 0xFF;
P5OUT = 0;
P5DIR = 0xFF;
P6OUT = 0;
P6DIR = 0xFF;
P7OUT = 0;
P7DIR = 0xFF;
P8OUT = 0;
P8DIR = 0xFF;
PJOUT = 0;
PJDIR = 0xFF;
//Enable internal pull-up/down resistors
P5REN |= BIT5 + BIT6;
//Required to set pull-up high resistor
P5OUT |= BIT5 + BIT6;
//Set P5.5 and P5.6 as input pins
P5DIR &= (~BIT5);
P5DIR &= (~BIT6);
//Falling Edge
P5IES = BIT5 + BIT6;
//Clear interrupt flags
P5IFG &= ~(BIT5 + BIT6);
//Enable interrupts
P5IE = BIT5 + BIT6;
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
__enable_interrupt();
while(1){
if (flag1 == 1){
P1OUT ^= BIT0;
flag1 = 0;
}
if (flag2 == 1){
P1OUT ^= BIT1;
flag2 = 0;
}
}
}
//Port 5 interrupt service routine
#pragma vector=PORT5_VECTOR
__interrupt void Port_1(void){
flag1 = 1;
flag2 = 1;
P5IFG &= ~(BIT5 + BIT6);
}
Thanks,
John