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.

LP-MSPM0L1306:About disabling interrupts

Part Number: LP-MSPM0L1306

#include "ti_msp_dl_config.h"

unsigned long   count_timer = 0;

extern volatile uint32_t interruptVectors[];

int main(void)
{
    SYSCFG_DL_init();
    DL_SYSCTL_enableSleepOnExit();
    NVIC_EnableIRQ(GPIO_SWITCHES_INT_IRQN);
    NVIC_EnableIRQ(COMPARE_0_INST_INT_IRQN);
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
    count_timer = 1500;
    while (1) {
        __WFI();
    }
}

void GROUP1_IRQHandler(void)
{
    uint32_t gpioA = DL_GPIO_getEnabledInterruptStatus
                         (GPIO_SWITCHES_PIN_18_PIN);

        if ((gpioA & GPIO_SWITCHES_PIN_18_PIN) ==
               GPIO_SWITCHES_PIN_18_PIN)
          {
            if (DL_GPIO_readPins(GPIO_SWITCHES_PORT, GPIO_SWITCHES_PIN_18_PIN ))
              {
               DL_TimerG_startCounter(COMPARE_0_INST);
               DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
               DL_GPIO_disableInterrupt(GPIOA, GPIO_SWITCHES_PIN_18_PIN);
              }

            DL_GPIO_clearInterruptStatus(GPIOA, GPIO_SWITCHES_PIN_18_PIN);
          }
}

void COMPARE_0_INST_IRQHandler(void)
{
    switch (DL_TimerG_getPendingInterrupt(COMPARE_0_INST)) {
        case DL_TIMER_IIDX_ZERO:
            if(count_timer>0)
            {
                count_timer = count_timer-1;
            }

            DL_TimerG_stopCounter(COMPARE_0_INST);



    if (count_timer == 0)
    {
        DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
        DL_GPIO_enableInterrupt(GPIOA, GPIO_SWITCHES_PIN_18_PIN);
        count_timer = 1500;
    }else if  (count_timer > 0)
    {
        DL_TimerG_startCounter(COMPARE_0_INST);
    }
    break;
            default:
                break;
    }
}

The intent of the code is that after detecting a GPIO interrupt, it starts a timer and repeats the timer operation for the set value of "count_timer",

and when "count_timer" reaches 0, the LED lights up. However, at this time, I would like to disable GPIO interrupts while repeating the timer operation.

However, there are some conditions in which the above code does not work properly.


After the timer starts operating (at this time, pin 18 is Low), before "count_timer" reaches 0, set the input of pin 18 to High again,

and if you continue to set it High until "count_timer" reaches 0, "count_timer" The moment it becomes 0 and DL_GPIO_enableInterrupt() is entered, another interrupt will occur and the timer will start working.


It seems that when DL_GPIO_enableInterrupt() operates, a pending GPIO interrupt is entered and a Timer interrupt is also entered.


When changing from disabling interrupts to enabling interrupts, how can I prevent pending interrupts from running and have interrupt triggers detected after enabling interrupts?


Are there any other settings required besides DL_GPIO_disableInterrupt() and DL_GPIO_enableInterrupt()?

  • I assume the glitch on your button may cause many interrupt. Can you use software to work around it, like add a counter in the IRQ. And control timer only when counter to be 1.

  • Could you please tell me more details?
    What code should I add?

    Also, regarding the GPIO interrupt disable/enable setting, am I correct in understanding that there is no additional code to add except for DL_GPIO_disableInterrupt() and DL_GPIO_enableInterrupt()?

  • Also, regarding the GPIO interrupt disable/enable setting, am I correct in understanding that there is no additional code to add except for DL_GPIO_disableInterrupt() and DL_GPIO_enableInterrupt()?

    Yes.

    You need to add a code to realize the method to filter the glitch on the button. So I suggest you to do like this. Remember to clear the count later manually.

    uint32_t count;

    void GROUP1_IRQHandler(void)
    {
    uint32_t gpioA = DL_GPIO_getEnabledInterruptStatus
    (GPIO_SWITCHES_PIN_18_PIN);

    count++;

    if ((gpioA & GPIO_SWITCHES_PIN_18_PIN) ==
    GPIO_SWITCHES_PIN_18_PIN)
    {
    if (DL_GPIO_readPins(GPIO_SWITCHES_PORT, GPIO_SWITCHES_PIN_18_PIN ))
    {

    if(count==1)

    {

    DL_TimerG_startCounter(COMPARE_0_INST);
    DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
    DL_GPIO_disableInterrupt(GPIOA, GPIO_SWITCHES_PIN_18_PIN);

    }

    DL_GPIO_clearInterruptStatus(GPIOA, GPIO_SWITCHES_PIN_18_PIN);
    }
    }