my change now:
Code: Select all
// set gpios
#define PIR_GPIO 17
#define BTN_GPIO 18
// change..
// Interrupt Number 22 // edit
// taken for extern edge from table
#define INT_NUMB 22 // edit
#define TAG 3
select each gpio..
Code: Select all
gpio_pad_select_gpio(PIR_GPIO);
gpio_pad_select_gpio(BTN_GPIO);
direction each gpio..
Code: Select all
/* Set the GPIO as a input */
gpio_set_direction(PIR_GPIO, GPIO_MODE_INPUT);
gpio_set_direction(BTN_GPIO, GPIO_MODE_INPUT);
pull each gpio..
Code: Select all
/* Set the GPIO pull */
gpio_set_pull_mode(PIR_GPIO, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(BTN_GPIO, GPIO_PULLUP_ONLY);
intr type for each gpio...
Code: Select all
gpio_set_intr_type(PIR_GPIO, GPIO_INTR_ANYEDGE);
gpio_set_intr_type(BTN_GPIO, GPIO_INTR_NEGEDGE);
i set here for each gpio enable the the isr
and this runs for me.
not sure that we "must" set only onetime
but this runs for me here:
enable intr each gpio..
Code: Select all
gpio_intr_enable(PIR_GPIO);
gpio_intr_enable(BTN_GPIO);
and here is my change...
only one registered isr callback for the "INTR_Numb 22"
i am sure we can set a second if we create a new with second INTR_NUMB like table.
register INTR_NUMB callback for ..
Code: Select all
// Intterrupt number see below
gpio_isr_register(INT_NUMB, gpioCallback, (void *)TAG);
runs for me like i need...
Code: Select all
1 Intr GPIO18 ,val: 0<\r><\n>
GPIO 18 request<\r><\n>
1 Intr GPIO18 ,val: 0<\r><\n>
GPIO 18 request<\r><\n>
1 Intr GPIO18 ,val: 0<\r><\n>
GPIO 18 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO18 ,val: 0<\r><\n>
GPIO 18 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO18 ,val: 0<\r><\n>
GPIO 18 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 0<\r><\n>
GPIO 17 request<\r><\n>
1 Intr GPIO17 ,val: 1<\r><\n>
GPIO 17 request<\r><\n>
any objection?
this
generates this panic*ed :
Code: Select all
c:/sdk32/esp-idf/components/freertos/./queue.c:603 (xQueueGenericSend)- assert failed!<\r><\n>
Guru Meditation Error: Core 0 panic'ed.<\r><\n>
Register dump:<\r><\n>
PC : Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.<\r><\n>
Register dump:<\r><\n>
PC : 40083456 PS : 00060033 A0 : 80083679 A1 : 3ffb5e70 <\r><\n>
A2 : 00000000 A3 : 00000002 A4 : 00000000 A5 : 00000000 <\r><\n>
A6 : 3f401044 A7 : 3ff4001c A8 : 0000007d A9 : 3ff4001c <\r><\n>
A10 : 3ff4001c A11 : 3f4002d0 A12 : 00000000 A13 : 3ffb5ed0 <\r><\n>
A14 : 00000000 A15 : 3f401158 SAR : 00000019 EXCCAUSE: 0000001c <\r><\n>
EXCVADDR: 00000004 LBEG : 4000c2e0 LEND : 4000c2f6 LCOUNT : 00000000 <\r><\n>
Rebooting...<\r><\n>
ets Jun 8 2016 00:22:57<\r><\n>
try a simple app code and make a system_restart();
..
best wishes
rudi
here my code:
Code: Select all
/******************************************************************************
*
* Espressif IoT Development Framework with the ESP32
*
* ESP-IDF -
* the new Espressif IoT Development Framework with ESP32 from espressif
* github : https://github.com/espressif/esp-idf
*
*
*******************************************************************************/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#define PIR_GPIO 17
#define BTN_GPIO 18
#define INT_NUMB 22 // edit
#define TAG 3
void gpioCallback (void* arg);
/******************************************************************************
* FunctionName : main_task
* Description :
* Parameters : void* pvParameter
* Returns : void
*******************************************************************************/
void main_task(void* pvParameter)
{
/* 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(PIR_GPIO);
gpio_pad_select_gpio(BTN_GPIO);
/* Set the GPIO as a input */
gpio_set_direction(PIR_GPIO, GPIO_MODE_INPUT);
gpio_set_direction(BTN_GPIO, GPIO_MODE_INPUT);
/* Set the GPIO pull */
gpio_set_pull_mode(PIR_GPIO, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(BTN_GPIO, GPIO_PULLUP_ONLY);
// gpio_set_intr_type(INPUT_GPIO, GPIO_INTR_NEGEDGE);
gpio_set_intr_type(PIR_GPIO, GPIO_INTR_ANYEDGE);
gpio_set_intr_type(BTN_GPIO, GPIO_INTR_NEGEDGE);
gpio_intr_enable(PIR_GPIO);
gpio_intr_enable(BTN_GPIO);
// Intterrupt number see below
gpio_isr_register(INT_NUMB, gpioCallback, (void *)TAG);
while(1) {
// printf( "Loop...\n" );
// vTaskDelay(1000 / portTICK_RATE_MS);
}
}
/******************************************************************************
* FunctionName : gpioCallback
* Description :
* Parameters : void* arg
* Returns :
*******************************************************************************/
void gpioCallback(void* arg)
{
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.
switch (gpio_num) {
case 17: ets_printf("GPIO 17 request\n"); break;
case 18: ets_printf("GPIO 18 request\n");
// fflush(stdout);
// system_restart();
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 = ; */
}
/******************************************************************************
* * * * * * * *: main of ESP32
* FunctionName : app_main
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void app_main()
{
nvs_flash_init();
system_init();
xTaskCreate(&main_task, "main_task", 2048, NULL, 5, NULL);
// system_restart();
}