How to use gpio_isr_register?
Re: How to use gpio_isr_register?
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?
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:
http://esp32.com/viewtopic.php?f=18&t=777
Thank you all for the help.
http://esp32.com/viewtopic.php?f=18&t=777
Thank you all for the help.
Re: How to use gpio_isr_register?
hi guys
have come back to the example but now few arguments:
old:
we need now 4 arguments?
http://esp-idf.readthedocs.io/en/latest ... r_handle_t
and other sequence for params?
best wishes
rudi
have come back to the example but now few arguments:
old:
Code: Select all
#define INT_NUMB 17
#define TAG 3
gpio_isr_register(INT_NUMB, gpioCallback, (void *)TAG);
http://esp-idf.readthedocs.io/en/latest ... 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 )
best wishes
rudi
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
Re: How to use gpio_isr_register?
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
hope we get not a general new-architecture in V2.
best wishes
rudi
there was re-architecture in the APIs and methods relating to interrupt service routines
so fast is code outdated
hope we get not a general new-architecture in V2.
best wishes
rudi
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪
-
- Posts: 60
- Joined: Mon Jun 26, 2017 5:36 am
Re: How to use gpio_isr_register?
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.
Thanks.
-
- Posts: 1
- Joined: Fri Oct 12, 2018 9:11 am
Re: How to use gpio_isr_register?
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..
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
#define ESP_INTR_FLAG_DEFAULT 0
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");
fflush(stdout);
system_restart();
}
/******************************************************************************
* 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);
break;
}
*/
}
// }
} 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 = ; */
gpio_num++;
}
/******************************************************************************
* * * * * * * *: main of ESP32
* FunctionName : app_main
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void app_main()
{
/* Calc */
nvs_flash_init();
system_init();
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
functions.)
*/
gpio_pad_select_gpio(INPUT_GPIO);
//gpio_pad_select_gpio(INPUT_GPIO1);
/* 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);
gpio_intr_enable(INPUT_GPIO);
//gpio_intr_enable(INPUT_GPIO1);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
// 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);
}
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: How to use gpio_isr_register?
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.
- 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.
Who is online
Users browsing this forum: MattWork and 113 guests