QuickLogic Thing+ Button Interrupt Issue: Function Not Executing on Press

Hi everyone,

I’m trying to set up an interrupt that triggers a function when the user button is pressed, but I’m having trouble getting it to work properly.

I’ve configured the interrupt to detect the button press and link it to a specific function. However, when I press the button, it seems like the function isn’t being called, or the interrupt isn’t being registered at all. I’ve double-checked my wiring and reviewed the code multiple times, but I can’t figure out what’s going wrong.

Has anyone else encountered a similar issue? Or does anyone have suggestions on what I might be missing or how I can troubleshoot this further? Any help would be greatly appreciated!

I should also mention that I’m not entirely sure what type of interrupt the button generates when pressed. The documentation for the QuickLogic Thing+ board isn’t very extensive. This lack of information is making it harder to troubleshoot the problem, so if anyone has experience with this board or knows where to find more detailed documentation, that would be really helpful!

This is my GPIO configuration:
GPIOCfgTypeDef gpiocfg_table =
{
{
.usPadNum = PAD_6,
.ucGpioNum = GPIO_0,
.ucFunc = PAD6_FUNC_SEL_SENS_INT_1,
.intr_type = LEVEL_TRIGGERED,
.pol_type = FALL_LOW,
.ucPull = PAD_NOPULL,
}
};

And this is the handler I think I linked to the interruption:

void SensorGpio_Handler(void)
{

 INTR_CTRL->GPIO_INTR_EN_M4 &= ~(GPIO_0_INTR);

userbutton();

INTR_CTRL->GPIO_0_INTR = 0;
NVIC_ClearPendingIRQ(Gpio_IRQn);

INTR_CTRL->GPIO_INTR_EN_M4 = GPIO_0_INTR;

}

I’m a student so I’m a little bit confused about all of this sorry if I make some stupid questions.
Thanks in advance!

That board is beyond my expertise, however, Claude.ai has a few suggestions that might help so I’m going to paste them below:

First, let’s review your GPIO configuration:

GPIOCfgTypeDef gpiocfg_table = {
    {
        .usPadNum = PAD_6,
        .ucGpioNum = GPIO_0,
        .ucFunc = PAD6_FUNC_SEL_SENS_INT_1,
        .intr_type = LEVEL_TRIGGERED,
        .pol_type = FALL_LOW,
        .ucPull = PAD_NOPULL,
    }
};

And the interrupt handler:

void SensorGpio_Handler(void) {
    INTR_CTRL->GPIO_INTR_EN_M4 &= ~(GPIO_0_INTR);
    
    userbutton();
    
    INTR_CTRL->GPIO_0_INTR = 0;
    NVIC_ClearPendingIRQ(Gpio_IRQn);
    
    INTR_CTRL->GPIO_INTR_EN_M4 = GPIO_0_INTR;
}

Based on this information, here are some potential issues and suggestions:

  1. Interrupt Configuration:
  • Make sure that the interrupt is properly enabled in the NVIC (Nested Vectored Interrupt Controller).
  • Verify that the interrupt priority is set correctly.
  1. GPIO Configuration:
  • Double-check that PAD_6 and GPIO_0 are the correct pins for your button.
  • Ensure that PAD6_FUNC_SEL_SENS_INT_1 is the correct function selection for interrupt mode.
  1. Interrupt Trigger:
  • You’ve configured it as LEVEL_TRIGGERED with FALL_LOW. This means it will trigger when the input falls to a low level. Make sure this matches your button’s behavior (i.e., the button should connect the pin to ground when pressed).
  1. Debouncing:
  • Mechanical buttons often need debouncing. Without it, you might get multiple interrupts for a single press.
  1. Handler Registration:
  • Ensure that SensorGpio_Handler is properly registered as the interrupt handler for GPIO_0.
  1. userbutton() Function:
  • Make sure the userbutton() function is defined and does what you expect.

Here’s a step-by-step troubleshooting plan:

  1. Verify Basic GPIO Functionality: First, let’s make sure the GPIO is working correctly without interrupts. Try this simple polling approach:
while(1) {
    if(GPIO_READ(GPIO_0) == 0) {  // Assuming active low
        // Button is pressed
        // Add a small delay for debouncing
        delay_ms(50);
        while(GPIO_READ(GPIO_0) == 0);  // Wait for button release
        userbutton();
    }
}
  1. Enable Debugging Output: Add some debug print statements in your interrupt handler:
void SensorGpio_Handler(void) {
    printf("Interrupt triggered!\n");
    INTR_CTRL->GPIO_INTR_EN_M4 &= ~(GPIO_0_INTR);
    
    userbutton();
    printf("userbutton() called\n");
    
    INTR_CTRL->GPIO_0_INTR = 0;
    NVIC_ClearPendingIRQ(Gpio_IRQn);
    
    INTR_CTRL->GPIO_INTR_EN_M4 = GPIO_0_INTR;
}
  1. Check Interrupt Registration: Make sure you’re registering the interrupt handler correctly. It might look something like this:
NVIC_SetVector(Gpio_IRQn, (uint32_t)SensorGpio_Handler);
NVIC_EnableIRQ(Gpio_IRQn);
  1. Verify Interrupt Enable: Ensure that the GPIO interrupt is enabled:
INTR_CTRL->GPIO_INTR_EN_M4 |= GPIO_0_INTR;
  1. Check for Conflicting Configurations: Make sure no other part of your code is modifying the GPIO or interrupt settings.

If none of these steps resolve the issue, it would be helpful to see more of your initialization code, particularly how you’re setting up the GPIO and registering the interrupt handler.

Regarding the documentation for the QuickLogic Thing+ board, you might want to check QuickLogic’s official website or GitHub repositories for more detailed information. Remember, debugging embedded systems often requires patience and systematic checking. Don’t hesitate to use debug print statements, LED indicators, or even an oscilloscope if available to understand what’s happening at each step!