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
#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);
}