This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R: The priority between 2 interrupts is not working, e.g. priority 0 interrupt does not trigger while priority 7 interrupt is executed

Part Number: MSP432P401R

Hello

First I am using The TI-RSLK robotics kit https://training.ti.com/ti-robotics-system-learning-kit with MSP432P401R launch pad on it. and my program uses LED1 on MSP432P401R LaunchPad™
Development Kit (MSP‑EXP432P401R) and the bumper switches on TI-RSLK chassis. 

I am creating a simple program to demonstrate the priority setting between interrupts. In my code I created 2 simple GPIO interrupts 1) The first interrupt is triggered by pressing switch 1 and light up LED1 on the on MSP432P401R LaunchPad, 2) the second interrupt is triggered if any of the bumper switches on TI-RSLK chassis is hit, where these switches are connected to port 4 on MSP432P401R LaunchPad. I set the priority of switch 1 interrupt to 7 (lowest) while bumper switches interrupt to 0 (highest). As shown bellow in my code both ISRs are very simple, toggle LED1 if switch 1 is pressed and toggle LED2 if any bumper switch is hit. I sat 2 breakpoints in each ISR; one at the first line which toggles the LED and the other at the second line which clear interrupt flag. To test the priority overriding of bumper interrupt over Switch 1 interrupt, I pushed the switch 1 button so interrupt 1 triggers and go to the first line in ISR 1 which toggles LED1, since there is a breakpoint at that line so before I hit continue I pressed one of the bumper switch buttons, so that before executing the second line it goes to ISR2 which has higher priority and after completing ISR2 it goes back to the second line of ISR1. However what really happened is that ISR1 continues normally and the 2nd line executed then the processing transfers to ISR2. This violates the expected priority overriding and I really do not know where is the problem is although my code is very simple. 

Any help would be very appreciated! Thanks in advance 

                 

/******************************************************************************
 * This program toggle LED1 when switch s1 is pressed (Red). While it toggles LED2 when Switch 2 is pressed (Blue)
 * When both switches are pressed LED2 (Purple) toggles
*******************************************************************************/

#include "driverlib.h"

#define LED2_PINS    GPIO_PIN2|GPIO_PIN1|GPIO_PIN0
#define BUMPER_PINS    GPIO_PIN0|GPIO_PIN2|GPIO_PIN3|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7

// P4.0,2,3,5,6,7 initialization
void BumperSwitchPort4_initialization_BasicMethod(){
    // configure P4.1 as GPIO
    /*P4->SEL0 &= 0x12; // setting pins 0,2,3,5,6,7 as GPIO
    P4->SEL1 &= 0x12;
    // make P4.0,2,3,5,6,7 in
    P4->DIR &= 0x12;
    // activate a resistor on that pin
    P4->REN |= 0xED;
    // make it pull up resistor
    P4->OUT |= 0xED;


    // Easier way
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN0);
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN2);
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN3);
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN5);
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN6);
    GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P4, GPIO_PIN7);*/

    // Easiest way
    GPIO_setAsOutputPin (GPIO_PORT_P4, BUMPER_PINS);

    return;
}


void BumperSwitches_Interrupt_Initialization(){
    // 7 steps of GPIO interrupt setup
//--------------------------------- start critical section --------------------------------------------------//
    // 2- Edge Select. In our case when any button is pressed low voltage will be input (falling edge)
    MAP_GPIO_interruptEdgeSelect (GPIO_PORT_P4, BUMPER_PINS, GPIO_HIGH_TO_LOW_TRANSITION);

    // 3- clear interrupt flag
    GPIO_clearInterruptFlag (GPIO_PORT_P4, BUMPER_PINS);

    // 4- enable the GPIO interrupt
    GPIO_enableInterrupt (GPIO_PORT_P4, BUMPER_PINS);

    // 5- Set priority
    Interrupt_setPriority (GPIO_PORT_P4, 0); // 0 is highest priority

    // 6- enable the interrupt in NVIC on port 1
    Interrupt_enableInterrupt(INT_PORT4);
//--------------------------------- end critical section --------------------------------------------------//
}

void LED2_Initialization(){
    /*MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0); // set P2.0 as output (P2.0 is connected to low power LED2 RED)
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1); // set P2.1 as output (P2.1 is connected to low power LED2 Green)
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2); // set P2.2 as output (P2.2 is connected to low power LED2 Blue)
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2);*/

    // Easiest way
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, LED2_PINS);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);

};

void LED1_Initialization(){
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); // set P1.0 as output (P1.0 is connected to low power LED1)
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); // initially off
};

void SW1_Initialization(){
    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); //Pin1.1 is connected to SW1
};

void SW1_Interrupt_Initialization(){
    // 7 steps of GPIO interrupt setup
//--------------------------------- start critical section --------------------------------------------------//
    // 2- Edge Select. In our case when any button is pressed low voltage will be input (falling edge)
    MAP_GPIO_interruptEdgeSelect (GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION);

    // 3- clear interrupt flag
    GPIO_clearInterruptFlag (GPIO_PORT_P1, GPIO_PIN1);

    // 4- enable the GPIO interrupt
    GPIO_enableInterrupt (GPIO_PORT_P1, GPIO_PIN1);

    // 5- Set priority
    Interrupt_setPriority (INT_PORT1, 7); // SW1 is linked to P1.1, and 0 is highest priority

    // 6- enable the interrupt in NVIC on port 1
    Interrupt_enableInterrupt(INT_PORT1);
//--------------------------------- end critical section --------------------------------------------------//
}

int main(void)
{

    WDT_A_holdTimer();

    LED1_Initialization();
    LED2_Initialization();

    SW1_Initialization();
    BumperSwitchPort4_initialization_BasicMethod();

    // 1- start critical section by disable all interrupts
    Interrupt_disableMaster();
    SW1_Interrupt_Initialization();
    BumperSwitches_Interrupt_Initialization();
    // 7- end of critical section, Enable interrupts that are already enabled
    MAP_Interrupt_enableMaster();

    while(1)
    {
        __WFI(); // Wait For Interrupt
    }
}


void PORT1_IRQHandler(void)
{
    MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);

    GPIO_clearInterruptFlag (GPIO_PORT_P1, GPIO_PIN1);
}


void PORT4_IRQHandler(void)
{
    MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, LED2_PINS);

    GPIO_clearInterruptFlag (GPIO_PORT_P4, BUMPER_PINS);
}

  

  •     Interrupt_setPriority (INT_PORT1, 7); // SW1 is linked to P1.1, and 0 is highest priority

    This function takes an actual priority byte, which has the priority in the high (for the MSP432) 3 bits, not the low 3 bits. The comments allude to this, but don't explain how to do it. The formulation you want is:

    > Interrupt_setPriority (INT_PORT1, 7 << (8U - __NVIC_PRIO_BITS)); // SW1 is linked to P1.1, and 0 is highest priority

    where __NVIC_PRIO_BITS=3, so the shift count is 5.

    I personally use NVIC_SetPriority(), which does this arithmetic for you.

    ----------

    Unsolicited: 

    > Interrupt_setPriority (GPIO_PORT_P4, 0); // 0 is highest priority

    This doesn't do what you want. It is either rejected by the function or sets some byte you don't want to set (I'm not sure which). Try:

    > Interrupt_setPriority (INT_PORT4, 0); // 0 is highest priority

  • Thanks a lot 

    That works

**Attention** This is a public forum