How to fix ESP-IDF error: GPIO isr service is not installed
Problem
You are trying to use the ESP-IDF GPIO interrupts API, but your ESP loop-crashes with the following error messages:
E (374) gpio: gpio_isr_handler_add(527): GPIO isr service is not installed, call gpio_install_isr_service() first
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x400d1584
file: "src/main.cpp" line 478
func: void app_main()
expression: gpio_isr_handler_add(rx_config.gpio_num, onDALIReceive, (void*)0 )
abort() was called at PC 0x40086117 on core 0
Solution
You need to call gpio_install_isr_service()
before you call gpio_isr_handler_add()
!
Here’s an example:
#include <driver/gpio.h>
void app_main() {
ESP_ERROR_CHECK(gpio_install_isr_service(0 /* No flags */));
// Now you can add your GPIO interrupt handlers
// ...
ESP_ERROR_CHECK(gpio_isr_handler_add(GPIO_NUM_2, myGPIOInterrupt, nullptr));
}
Note that calling gpio_install_isr_service()
is fundamentally incompatible with using the gpio_set_intr_type()
function. So you can’t use both in the same project.