I'm programming in C on an MSP432 using Code Composer Studio v8.2.0.
Now I am writing an interrupt to use 4 different buttons to increment and decrement a variable. The code below cuts out two of those buttons and is simply trying to increment or decrement a variable (TEST) by a value of 2 whenever one of these two buttons are pressed.
I've written some interrupts for some rotary encoders that work perfectly. As far as I can tell I have used the same exact code (other than obvious changes to make it for buttons instead of encoders) but this isn't working.
Buttons are on P1.1 (edit: said 1.2) and P1.4. This code throws up no errors but the interrupt never gets triggered by either of the buttons and therefor, the variable doesn't change values at all.
I've lost track as to what I've tried at this point. Its been hounding me for about 5 hours now.
#include "msp.h"
#include "driverlib.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "grlib.h"
#include "button.h"
#include "imageButton.h"
#include "radioButton.h"
#include "checkbox.h"
#include <LcdDriver/kitronix320x240x16_ssd2119_spi.h>
#include "images/images.h"
int TEST = 0;
int main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
boardInit();
clockInit();
initializeOptionsMenuButtons();
__enable_interrupt();
//Navigation Testing IO
__disable_irq();
P1->SEL1 &= ~0x12; // select io function: P1.2 & P1.4
P1->SEL0 &= ~0x12;
P1->DIR &= ~0x12; // set inputs
P1->REN |= 0x12; // enable pull resistors for P1.2 & P1.4
P1->OUT &= ~0x12; // need to set P2.3-P2.6 to low so PULLDOWN resistor will be selected
P1->IES &= ~0x12; // select low to high transition for interrupt
P1->IFG = 0; // clear interrupt register
P1->IE |= 0x12; // enable interrupt for P1.2 & P1.4
NVIC_SetPriority(PORT1_IRQn,3);
NVIC_EnableIRQ(PORT1_IRQn);
__enable_irq();
for(;;){
}
}
void PORT1_IRQHandler(void) {
if( P1->IFG & 0x02 ) { // UP (2.3) triggers interrupt
if ( 2 <= TEST <= 11 ) {
TEST = TEST - 2;
}
}
if( P1->IFG & 0x10 ) { // DOWN (2.4) triggers interrupt
if ( TEST <= 9 ) {
TEST = TEST + 2;
}
}
P1->IFG &= ~0x12;
}
Depending on which button is pushed, the variable called TEST should increment or decrement by 2. As I said before, this does not happen because my interrupt that they are housed inside of does not trigger.
Any help is greatly appreciated. I'm out of ideas.