Page 5 of 5

Re: How to use gpio_isr_register?

Posted: Tue Dec 20, 2016 6:55 am
by phando
ESP_Sprite, Thanks for the link. I followed the docs to the best of my ability. I am trying to hook a button up to an esp32. Is using interrupts the right way to go about this? On the NodeMCU I set up interrupts any time I needed triggers on GPIO pins. If anyone has an example of a tigger and button it would freaking awesome.

Re: How to use gpio_isr_register?

Posted: Wed Dec 21, 2016 6:53 am
by phando
For what it is worth, I figured it out with one issue. The interrupt is working now, but I am not able to set EDGE or HIGH as an interrupt flag. There is sample code and a brief write-up here:

Thank you all for the help.

Re: How to use gpio_isr_register?

Posted: Tue Feb 14, 2017 11:34 pm
by rudi ;-)
hi guys

have come back to the example but now few arguments:


Code: Select all

#define INT_NUMB 17 
#define TAG 3 

gpio_isr_register(INT_NUMB, gpioCallback, (void *)TAG);

we need now 4 arguments? ... r_handle_t

Code: Select all

esp_err_t gpio_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, gpio_isr_handle_t *handle )
and other sequence for params?

best wishes
rudi ;-)

Re: How to use gpio_isr_register?

Posted: Wed Feb 15, 2017 12:22 am
by rudi ;-)
ok, just in time, sorted it out and runs again.

there was re-architecture in the APIs and methods relating to interrupt service routines

so fast is code outdated :mrgreen:

hope we get not a general new-architecture in V2.

best wishes
rudi ;-)

Re: How to use gpio_isr_register?

Posted: Thu Oct 05, 2017 1:26 pm
by Trialblazer47
how to use new API I am not able to understand. I want to use an input pulled up with push button that will enable Blufi advertising . So I am thinking of updating a flag in interrupt routine but I don't understand isr function. Please explain allocation flag and handle.

Re: How to use gpio_isr_register?

Posted: Fri Oct 12, 2018 9:16 am
by nagarathna
hi I am using 2 gpio for two separate interrupt but i am getting only one interrupt at a time please any one can help me out please..

bellow in my code..

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/gpio.h"

#define INPUT_GPIO 17
#define INPUT_GPIO 18

#define TAG 3

void gpioCallback (void* arg);

 * FunctionName : hello_task
 * Description  :
 * Parameters   : void* pvParameter
 * Returns      :
void hello_task(void* pvParameter)
  /* Calc */
  printf("Hello, how are you?!\n");
      for (int i = 10; i >= 0; i--) {
          printf("Restarting in %d seconds...\n", i);
          vTaskDelay(1000 / portTICK_RATE_MS);
      printf("Restarting now.\n");

 * FunctionName : gpioCallback
 * Description  :
 * Parameters   : void* arg
 * Returns      : 
void gpioCallback(void* arg)
  /* Calc */
  uint32_t gpio_num = 0;
    uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);   //read status to get interrupt status for GPIO0-31
    uint32_t gpio_intr_status_h = READ_PERI_REG(GPIO_STATUS1_REG);//read status1 to get interrupt status for GPIO32-39
    SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status);    //Clear intr for gpio0-gpio31
    SET_PERI_REG_MASK(GPIO_STATUS1_W1TC_REG, gpio_intr_status_h); //Clear intr for gpio32-39
   do {
      if(gpio_num < 32) {
        if(gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio31
      ets_printf("1 Intr GPIO%d ,val: %d\n",gpio_num,gpio_get_level(gpio_num));
           //This is an isr handler, you should post an event to process it in RTOS queue.
         // * test your self......
         switch (gpio_intr_status & BIT(gpio_num)) {
            case 17: printf("GPIO 17 request\n"); break;
                  //  xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
            case 18: printf("GPIO 18 request : task2 call\n");
                  xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
      // }
      } else {
        if(gpio_intr_status_h & BIT(gpio_num - 32)) {
          ets_printf("2 Intr GPIO%d, val : %d\n",gpio_num,gpio_get_level(gpio_num));
          //This is an isr handler, you should post an event to process it in RTOS queue.
 } while(gpio_num++ < GPIO_PIN_COUNT);
  /* push_status = ; */

 * * * * * * * *: main of ESP32
 * FunctionName : app_main
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
void app_main() 
  /* Calc */
gpio_isr_handle_t *handle = NULL;
  /* Calc */
  /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
         muxed to GPIO on reset already, but some default to other
         functions and need to be switched to GPIO. Consult the
         Technical Reference for a list of pads and their default


     /* Set the GPIO as a input */
      gpio_set_direction(INPUT_GPIO, GPIO_MODE_INPUT);
      //gpio_set_direction(INPUT_GPIO1, GPIO_MODE_INPUT);

     /* Set the GPIO pull */
      gpio_set_pull_mode(INPUT_GPIO, GPIO_PULLUP_ONLY);
   //  gpio_set_pull_mode(INPUT_GPIO1, GPIO_PULLUP_ONLY);

      // gpio_set_intr_type(INPUT_GPIO, GPIO_INTR_NEGEDGE);
       gpio_set_intr_type(INPUT_GPIO, GPIO_INTR_ANYEDGE);
    //pio_set_intr_type(INPUT_GPIO1, GPIO_INTR_ANYEDGE);



      // Intterrupt number see below
//      gpio_isr_register(INPUT_GPIO, gpioCallback, (void *)TAG, handle); // 17

        gpio_isr_handler_add(INPUT_GPIO, gpioCallback, 1 );
  //    gpio_isr_handler_add(INPUT_GPIO1,  gpioCallback, 2 );

//   xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
  //askCreate(&main_task, "main_task", 2048, NULL, 5, NULL);

Re: How to use gpio_isr_register?

Posted: Sat Oct 13, 2018 4:07 am
by ESP_Sprite
Few things:
- You're missing the break after the gpio17 case in the select
- Please do not call anything that does not have _from_ISR or something like that from an ISR. It will not work and/or crash in various interesting and wonderful ways.