ESP IDF GPIO Interrupt
Posted: Thu Dec 16, 2021 8:49 am
Hello,
I am trying to configure the two GPIO pins on my custom ESP32S2 board (connected to a switch ) as interrupts.
But the values I read from the pins after configurations are quiet strange. Can someone please help me to figure out whats going wrong here.
Thank you
[Codebox]void app_main()
{
//zero-initialize the config structure.
gpio_config_t io_conf;
//SwitchA Interrupt
io_conf.intr_type = GPIO_INTR_ANYEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = 1UL<<SwitchA;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//SwitchB Interrupt
io_conf.intr_type = GPIO_INTR_ANYEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = 1UL<<SwitchB;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//change gpio interrupt type for one pin
gpio_set_intr_type(SwitchA, GPIO_INTR_ANYEDGE);
//change gpio interrupt type for one pin
gpio_set_intr_type(SwitchB, GPIO_INTR_ANYEDGE); //create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task, "gpio_task", 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(SwitchA, gpio_isr_handler, (void*) SwitchA);
gpio_isr_handler_add(SwitchB, gpio_isr_handler, (void*) SwitchB);
[/Codebox]
I am trying to configure the two GPIO pins on my custom ESP32S2 board (connected to a switch ) as interrupts.
But the values I read from the pins after configurations are quiet strange. Can someone please help me to figure out whats going wrong here.
Thank you
[Codebox]void app_main()
{
//zero-initialize the config structure.
gpio_config_t io_conf;
//SwitchA Interrupt
io_conf.intr_type = GPIO_INTR_ANYEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = 1UL<<SwitchA;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//SwitchB Interrupt
io_conf.intr_type = GPIO_INTR_ANYEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = 1UL<<SwitchB;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
//change gpio interrupt type for one pin
gpio_set_intr_type(SwitchA, GPIO_INTR_ANYEDGE);
//change gpio interrupt type for one pin
gpio_set_intr_type(SwitchB, GPIO_INTR_ANYEDGE); //create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task, "gpio_task", 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(SwitchA, gpio_isr_handler, (void*) SwitchA);
gpio_isr_handler_add(SwitchB, gpio_isr_handler, (void*) SwitchB);
[/Codebox]