# GPIO Interrupt Causes CPU Exception on Some Pins

**URL:** <https://forum.amebaiot.com/t/gpio-interrupt-causes-cpu-exception-on-some-pins/4202>\
**Category:** Peripherals\
**Tags:** rtl8735b\
**Created:** [June 25, 2025, 9:01am UTC](https://forum.amebaiot.com/t/gpio-interrupt-causes-cpu-exception-on-some-pins/4202 "2025-06-25T09:01:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Howard](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/howard/32/2079_2.png) [@Howard](https://forum.amebaiot.com/u/Howard)\
**Post date:** [June 25, 2025, 9:01am UTC](https://forum.amebaiot.com/t/gpio-interrupt-causes-cpu-exception-on-some-pins/4202/1 "2025-06-25T09:01:24Z")

</div>

Dear Ameba Team,

I’m currently working on enabling GPIO interrupts on several pins, but I encountered CPU exceptions during testing. After evaluating each GPIO pin, I found that the following pins consistently fail when interrupts are enabled:

- **D15** (GPIOE\_1): Cannot read after GPIO interrupt is enabled
- **D18** (GPIOD\_16): Cannot read after GPIO interrupt is enabled
- **D19** (GPIOD\_15): Cannot read after GPIO interrupt is enabled
- **D20** (GPIOD\_14): Cannot read after GPIO interrupt is enabled

It seems enabling interrupts on these specific pins results in abnormal behavior or even system crashes.

Could you please help identify the cause and provide a way to make these pins work properly with GPIO interrupts?

I’ve also attached a test file for verifying GPIO behavior. The issue only occurs when **D15, D18, D19, or D20** are included in the interrupt test.  
If the test excludes these pins — for example:

```
      if ((i!=15) && (i!=18) && (i!=19) && (i!=20))

```

then **no exceptions occur** , and everything works as expected.  
However, if any of these pins are included, the CPU exception is triggered.

[GPIOReadTest.zip](https://forum.amebaiot.com/uploads/short-url/5MRzFvtfqeU9eEmLwXMvzR5RcNr.zip) (549 位元組)

---

<div class="post-metadata">

**Author:** ![KaiFai\_Y](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kaifai_y/32/2252_2.png) [@KaiFai\_Y](https://forum.amebaiot.com/u/KaiFai_Y)\
**Post date:** [June 26, 2025, 3:20am UTC](https://forum.amebaiot.com/t/gpio-interrupt-causes-cpu-exception-on-some-pins/4202/2 "2025-06-26T03:20:41Z")

</div>

Hi @Howard , your GPIOReadTest i saw you are calling `digitalRead()` after `pinMode(pin, INPUT_IRQ_CHANGE)` can cause conflicts internally. You may test with this to see all the enabling interrupts. Thank you.

```auto
#include "gpio_irq_api.h"

typedef struct {
    const char* label;
    PinName pin;
} GpioPinInfo;

GpioPinInfo testPins[] = {
    {"D0 (PF5)", PF_5},
    {"D1 (PF6)", PF_6},
    {"D2 (PF7)", PF_7},
    {"D3 (PF8)", PF_8},
    {"D4 (PF11)", PF_11},
    {"D5 (PF12)", PF_12},
    {"D6 (PF13)", PF_13},
    {"D7 (PF14)", PF_14},
    {"D8 (PF15)", PF_15},
    {"D9 (PF2)", PF_2},
    {"D10 (PF1)", PF_1},
    {"D11 (PF0)", PF_0},
    {"D12 (PE4)", PE_4},
    {"D13 (PE3)", PE_3},
    {"D14 (PE2)", PE_2},
    {"D15 (PE1)", PE_1},
    {"D16 (PD18)", PD_18},
    {"D17 (PD17)", PD_17},
    {"D18 (PD16)", PD_16},
    {"D19 (PD15)", PD_15},
    {"D20 (PD14)", PD_14},
    {"D21 (PA2)", PA_2},
    {"D22 (PA3)", PA_3}
};

void dummy_handler(uint32_t id, gpio_irq_event event) {
    Serial.print("Interrupt on pin index: ");
    Serial.println(id);
}

void setup() {
    Serial.begin(115200);
    delay(1000);
    Serial.println("=== GPIO IRQ Capability Test ===");

    for (int i = 0; i < sizeof(testPins) / sizeof(testPins[0]); i++) {
        gpio_irq_t irq;
        int result = gpio_irq_init(&irq, testPins[i].pin, dummy_handler, i);
        if (result == 0) {
            Serial.println(testPins[i].label);
            gpio_irq_free(&irq); // Clean up
        } else {
            Serial.println(testPins[i].label);
        }
    }

    Serial.println("=== Test Complete ===");
}

void loop() {
    // Nothing to do
}

```
