this is the same question i have.
i have mean, that my finger dip is to sensitive - so i change to buttons and pulled up with 10k.
sometimes i get valu= high, but i have set INTR to low. ( NEGEDGE ) so i ask me, why this can happens that i get high valu in the isr.
at this time i work just in time to search why this is.
simple answere
ok runs for me now on this fast selftest:
set up gpio 17, 18 for input and ISR
set up gpio 16, 23 for output and connect 16->17 and 23->18
create push1 task ( delay times arbitrarily )
create push2 task ( delay times arbitrarily )
setup the INTR to NEGEDGE for test no valu=high in ISR
-> debouncing is recommendable must be done if you push by finger, buttons on all occasions
( here for fast test by gpio outputs as "pushes" not done )
simple output:
Code: Select all
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
result:
no high in the ISR = ok
no bouncing = ok
here the simple ( not cleaned ) 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 PUSH1_GPIO 16 // connected to PIR_GPIO '17
#define PUSH2_GPIO 23 // connected to BTN_GPIO '18
#define PIR_GPIO 17
#define BTN_GPIO 18
#define INT_NUMB 17 // 22
#define TAG 3 // still i used here
void gpioCallback (void* arg);
/******************************************************************************
* FunctionName : main_task
* Description :
* Parameters : void* pvParameter
* Returns : void
*******************************************************************************/
void main_task(void* pvParameter)
{
/* 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(PIR_GPIO, GPIO_INTR_ANYEDGE);
// gpio_set_intr_type(BTN_GPIO, GPIO_INTR_ANYEDGE);
gpio_set_intr_type(PIR_GPIO, GPIO_INTR_NEGEDGE);
gpio_set_intr_type(BTN_GPIO, GPIO_INTR_NEGEDGE);
// ETS_GPIO_INTR_DISABLE() ;
gpio_intr_enable(PIR_GPIO);
gpio_intr_enable(BTN_GPIO);
// gpio_intr_enable();
// ETS_GPIO_INTR_ENABLE();
// ETS_INTR_ENABLE();
// 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)
{
gpio_intr_disable(PIR_GPIO);
gpio_intr_disable(BTN_GPIO);
uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG); //read status to get interrupt status for GPIO0-31
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status); //Clear intr for gpio0-gpio31
switch (gpio_intr_status) {
// BTN_GPIO
// GPIO 18
// 1000000000000000000
case 262144: // gpio_intr_disable(PIR_GPIO);
// gpio_intr_disable(BTN_GPIO);
ets_printf("1 Intr GPIO%d ,val: %d\n",gpio_intr_status,gpio_get_level(BTN_GPIO));
ets_printf("GPIO 18 [BTN] pushed\n");
break;
// PIR_GPIO
// GPIO 17
// 100000000000000000
case 131072: // gpio_intr_disable(PIR_GPIO);
// gpio_intr_disable(BTN_GPIO);
ets_printf("2 Intr GPIO%d ,val: %d\n",gpio_intr_status,gpio_get_level(PIR_GPIO));
ets_printf("GPIO 17 [PIR] pushed\n");
break;
default: ets_printf("handler : %lu fired\n", gpio_intr_status);
}
gpio_intr_enable(PIR_GPIO);
gpio_intr_enable(BTN_GPIO);
}
void push1_task(void *pvParameter)
{
/* Set the GPIO as a push/pull output */
gpio_set_direction(PUSH1_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Push1 off (output low) */
gpio_set_level(PUSH1_GPIO, 0);
vTaskDelay(732 / portTICK_RATE_MS);
/* Push1 on (output high) */
gpio_set_level(PUSH1_GPIO, 1);
vTaskDelay(492 / portTICK_RATE_MS);
}
}
void push2_task(void *pvParameter)
{
/* Set the GPIO as a push/pull output */
gpio_set_direction(PUSH2_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Push2 off (output low) */
gpio_set_level(PUSH2_GPIO, 0);
vTaskDelay(472 / portTICK_RATE_MS);
/* Push2 on (output high) */
gpio_set_level(PUSH2_GPIO, 1);
vTaskDelay(839 / portTICK_RATE_MS);
}
}
/******************************************************************************
* * * * * * * *: 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);
xTaskCreate(&push1_task, "push1_task", 512, NULL, 5, NULL);
xTaskCreate(&push2_task, "push2_task", 512, NULL, 5, NULL);
}
runs for me now like i need and controlled by eyes,
next step comes with RÌGOL / LOGANALYSER
thanks WiFive for INTR_NUM info,
have now understand what ESP_Sprite have warned with explanation
INTR_NUMB 17 and GPIO 17 was coincidence that works.
this only a simple test here.
i will test with fast handshakes and d0..d7 between 2 esp32 and more.
think the base in ISR/INTR now understand.
have noted, that we have now more function
example if we enable each
gpio_intr_enable(GPIO_XX);
gpio_intr_enable(GPIO_YY);
then we can "Evaluate only one of the two" in the ISR, because the INTR Fired onetimes to this time..
if we want "Evaluate all " / we can "Evaluate all" in the ISR because the INTR Fired onetimes, and if was "pushed" the other before, we can see this if we READ_PERI_REG(GPIO_STATUS_REG);
this is very fine if we example make INTR on SDA ( I2C ) and want check SCL too on a certaintime for a CMD ( START, STOP ) without a INTR enable on this.
best wishes
rudi
btw:
one question is for me open:
what is the best for use and what is real the difference of this?
17 extern level
22 extern edge