Faced a problem while handling a button click with an external interrupt. I initialized the pin on which the button is located as a falling edge interrupt. However, when the button is pressed, the interrupt is triggered both on the falling edge and on the rising edge. The button is pulled up to power supply through an external 5.1 kΩ resistor and a capacitor is connected in parallel with the button to suppress bounce.
Here is my code:
Code: Select all
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
xTaskHandle Test_Task_Handle;
// interrupt handler function
static void IRAM_ATTR isr_button_pin_heandler(void* arg)
{
BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyFromISR(Test_Task_Handle, 0, eNoAction, &pxHigherPriorityTaskWoken);
if (pxHigherPriorityTaskWoken == pdTRUE)
portYIELD_FROM_ISR();
}
void Test_Task(void*);
void app_main(void)
{
// config interrupt pin
gpio_config_t button_conf = {
.intr_type = GPIO_INTR_NEGEDGE,
.mode = GPIO_MODE_INPUT,
.pin_bit_mask = (1ULL << GPIO_NUM_14),
.pull_down_en = 0,
.pull_up_en = 0,
};
gpio_config(&button_conf);
gpio_install_isr_service(ESP_INTR_FLAG_LEVEL1);
gpio_isr_handler_add(GPIO_NUM_14, isr_button_pin_heandler, (void*)GPIO_NUM_14);
// config LED pin
gpio_config_t led_pin_conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1ULL << GPIO_NUM_23),
.pull_down_en = 0,
.pull_up_en = 0,
};
gpio_config(&led_pin_conf);
xTaskCreate(Test_Task, "Test_Task", 5000, NULL, 1, &Test_Task_Handle);
}
void Test_Task(void* pvParameters)
{
bool flag = false;
for (;;)
{
xTaskNotifyWait(0x00, LONG_MAX, NULL, portMAX_DELAY);
flag = !flag;
gpio_set_level(GPIO_NUM_23, flag);
}
}