如何修复 ESP-IDF 错误:GPIO isr service is not installed
问题
你尝试使用 ESP-IDF GPIO 中断 API,但你的 ESP 循环崩溃并显示以下错误消息:
gpio_isr_error_log.txt
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解决方案
你需要在调用 gpio_isr_handler_add() 之前调用 gpio_install_isr_service()!
这是一个示例:
gpio_install_isr_service.cpp
#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));
}注意,调用 gpio_install_isr_service() 与使用 gpio_set_intr_type() 函数根本不兼容。所以你不能在同一项目中同时使用两者。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow