GPIO interrupt not working
Posted: Thu Jan 25, 2024 11:45 am
Dear ESP-Forum Members,
for my project I need a GPIO interrupt (pressed botton). I selected the GPIO25 pin connect it though the switch to the ground. The negative edge should start the isr. Message from the GPIO configurator:
I adapted the ESP-example-code for my needs:
But when I press the switch to trigger the isr, the ESP32 is restarting and the monitor get this printout:
I added some ESP_LOGs in the isr. These outputs are not visible, so the problem accurs befor the isr is starting.
I have no idea what could be wrong. I assume it could be a storage problem.
I attached the complete monitor printout. Please help me to interprete the error message to find the root cause for the problem.
Thank you for your support.
Greetings
Henry
for my project I need a GPIO interrupt (pressed botton). I selected the GPIO25 pin connect it though the switch to the ground. The negative edge should start the isr. Message from the GPIO configurator:
I (2283) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2
I adapted the ESP-example-code for my needs:
Code: Select all
#define GPIO_OK_Button 25
#define ESP_INTR_FLAG_DEFAULT 0
static const char *TAG = "HE_Ctrl";
static bool ok_pressed;
static QueueHandle_t gpio_evt_queue = NULL;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
ESP_LOGI(TAG, "gpio_isr_before queuesend");
ESP_LOGI(TAG, "isr_arg: %lX", (uint32_t) arg);
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
ESP_LOGI(TAG, "gpio_isr_after queuesend");
}
static void OK_task(void* arg)
{
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
vTaskDelay(100 / portTICK_PERIOD_MS);
printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num));
ok_pressed = true;
}
}
}
static void init_ok_button(void)
{
ok_pressed = false;
//zero-initialize the config structure.
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_NEGEDGE;
io_conf.pin_bit_mask = 1ULL<<GPIO_OK_Button;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
ESP_LOGI(TAG, "BitMask: %LX", io_conf.pin_bit_mask);
// create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
// start gpio task
xTaskCreate(OK_task, "gpio_task_example", 2048, NULL, 10, NULL);
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_OK_Button, gpio_isr_handler, (void*) GPIO_OK_Button);
printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size());
ESP_LOGI(TAG, "gpio_initialized");
}
But when I press the switch to trigger the isr, the ESP32 is restarting and the monitor get this printout:
abort() was called at PC 0x40083043 on core 0
Backtrace: 0x40081ac6:0x3ffb1770 0x40089d6d:0x3ffb1790 0x40091686:0x3ffb17b0 0x40083043:0x3ffb1820 0x40083181:0x3ffb1850 0x400831fa:0x3ffb1870 0x4014a23a:0x3ffb18a0 0x4014d3a9:0x3ffb1bc0 0x401597d1:0x3ffb1bf0 0x4009004d:0x3ffb1c20 0x4008379d:0x3ffb1c70 0x400838b2:0x3ffb1ca0 0x40083942:0x3ffb1cd0 0x40082e35:0x3ffb1d00 0x40088b3f:0x3ffbcd00 0x400d370b:0x3ffbcd20 0x4008af41:0x3ffbcd40 0x4008c74d:0x3ffbcd60
ELF file SHA256: 43476a0f78228a12
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
I added some ESP_LOGs in the isr. These outputs are not visible, so the problem accurs befor the isr is starting.
I have no idea what could be wrong. I assume it could be a storage problem.
I attached the complete monitor printout. Please help me to interprete the error message to find the root cause for the problem.
Thank you for your support.
Greetings
Henry