I'm trying to code my own little program for the ESP. I try to use gpio interrupts instead of polling.
Now, when I press the button and pull the gpio low, the interrupt function gets called... but the problem is, it gets called twice. Therefore I tried to disable interrupts in the beginning of the function and reenable it when it's done, but that doesn't fix it.
Here is my code:
#include <ets_sys.h>
#include <osapi.h>
#include <gpio.h>
void interupt_test() {
ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
//wdt_feed();
uint32 gpio_status;
gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
//clear interrupt status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
ets_uart_printf("GPIO Interrupt!\r\n");
GPIO_OUTPUT_SET(2, 0);
ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
}
void ICACHE_FLASH_ATTR gpio_init() {
ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
ETS_GPIO_INTR_ATTACH(interupt_test, 12); // GPIO12 interrupt handler
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); // Set GPIO12 function
gpio_output_set(0, 0, 0, GPIO_ID_PIN(12)); // Set GPIO12 as input
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(12)); // Clear GPIO12 status
gpio_pin_intr_state_set(GPIO_ID_PIN(12), 1); // Interrupt on any GPIO12 edge
ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
//wdt_feed();
}
Looking at the serial console, I can see the message "GPIO Interrupt!" twice... any ideas how to fix that or what causes this problem ?
Kind regards,
Jannik Jung