Other Parts Discussed in Thread: MSP-EXP430FR5994
Tool/software: Code Composer Studio
I am trying to use interrupts for the two switches (S1 and S2, or P5.6 and P5.5) on the MSP-EXP430FR5994 development kit. As soon as the interrupts are enabled the ISR starts even though neither of the switches has been pressed. The value of the interrupt flag is zero (no interrupts set) before the interrupts are enabled but the value is 255 (all interrupts set) immediately inside the ISR until I reset flags 5 and 6 (then the flag is 159, i.e., bits 5 and 6 turned off). Once a switch is pressed nothing seems to happen.
Why is the interrupt flag equal to 255 as soon as the interrupts are enabled? I assume this is why the ISR is activated immediately without waiting for a switch to be pressed.
I imagine the solution is rather trivial but I'm stumped. Any help would be appreciated.
#include <msp430.h>
#include "driverlib.h"
#include "gpio.h"
#include "stdio.h"
#include "string.h"
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure LEDs and switches
P1DIR |= BIT0; // Set P1.0 to output
P1DIR |= BIT1; // Set P1.1 to output
P1OUT &= ~BIT0; // set P1.0 to Off (red LED)
P1OUT &= ~BIT1; // set P1.1 to Off (green LED)
P5IE |= BIT5; // P5.5 interrupt enabled (S2)
P5IE |= BIT6; // P5.6 interrupt enabled (S1)
P5IFG &= ~BIT5; // P5.5 interrupt flag cleared (S2)
P5IFG &= ~BIT6; // P5.6 interrupt flag cleared (S1)
__bis_SR_register(GIE); // Enable all interrupts
// Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
while(1) {;}
}
#pragma vector=PORT5_VECTOR
__interrupt void Port_5(void)
{
// For now, just toggle each LED, eventually be more specific w.r.t. the switch pressed.
P1OUT ^= BIT0; // Toggle P1.0
P1OUT ^= BIT1; // Toggle P1.1
P5IFG &= ~BIT5; // P5.5 interrupt flag cleared
P5IFG &= ~BIT6; // P5.6 interrupt flag cleared
}