Part Number: MSP432P401R
I am trying to write some simple code to turn an on-board LED on and off using the two switches on the Launchpad. However, as soon as I enable interrupts on Port 1 Pin 4, the interrupt flag is raised. This pin is connected to Switch 2 on the Launchpad which is normally open and connects the pin to GND when it is closed. I started doing some experimenting and this also happens when I enable interrupts on Port 1 Pin 5 which is not connected to any button. I've played around with several different configurations and I simply cannot figure out why the interrupt is occurring as soon as I enable it. Port 1 Pin 1 has the exact same register and switch configuration and does not behave in this way.
I initially wrote the code using TI's driverlib for the MSP432 and then wrote it a second time by just setting the register value. Both pieces of code had the same problem.
I have tried both rising edge triggering with the pin configured as input with pulldown and falling edge interrupt triggering with the pin configured as input with a pullup and both have the same issue. I know on MSP430s, you have to clear the interrupt as the register initializes to the flag being set. However, the P1IFG register initializes to all the flags not asserted.
Here is the code:
void main(void) { WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer /* S1 */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); /* S2 */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); /* Red LED */ GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION); // Upper 3 bits control hardware priority, lower 7 bits control sub-priority Interrupt_setPriority(INT_PORT1, 0xC0); GPIO_registerInterrupt(GPIO_PORT_P1, inputIRQHandler); interrupts = GPIO_getEnabledInterruptStatus(GPIO_PORT_P1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); /* Register Level Code P1->SEL0 &= ~BIT4; P1->SEL1 &= ~BIT4; P1->DIR &= ~BIT4; P1->OUT |= BIT4; P1->REN |= BIT4; P1->IES |= BIT4; P1->IE |= BIT4; */ Interrupt_enableMaster(); while(1); } void inputIRQHandler(void) { uint_fast16_t interrupts; interrupts = GPIO_getEnabledInterruptStatus(GPIO_PORT_P1); if (interrupts & GPIO_PIN1) { GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); } if (interrupts & GPIO_PIN4) { GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN4); GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); } }
Any thoughts?