- IRAM_ATTR static void ISR_Door_Sensor_Interrupt(void* arg)
- {
- /* disable the interrupt to try to eliminate the reciprocal edge interrupt */
- gpio_intr_disable(door_sensor);
- xSemaphoreGiveFromISR(gpio_door_sensor_semaphore, NULL);
- }
Important Note: For an ESP32, GPIO Inputs that are added to the underlying interrupt service driver become “shared interrupts” and will cause an interrupt to be generated for both a Negative Edge AND a Positive Edge (ANY EDGE). So, the code sees 2 interrupts for every button press/release regardless of the config setup. That’s just the way it is!!!!
wifi device code:
ISR:
- static void TASK_Handle_GPIO_Door_Sensor_Interrupt(void* arg)
- {
- uint16_t door_history = 0b1111111111111111;
- int check_count = 0;
- int LOW = 0;
- int HIGH = 1;
- for(;;)
- {
- if(xSemaphoreTake(gpio_door_sensor_semaphore, portMAX_DELAY) == pdTRUE)
- {
- check_count = 0;
- door_history = 0b1111111111111111;
- while(check_count < 16)
- {
- door_history = door_history << 1;
- door_history |= gpio_get_level(door_bell);
- check_count += 1;
- vTaskDelay(5 / portTICK_PERIOD_MS);
- /* total debounce time 80 mSec + instruction processing time */
- }
- }
- /* only looking at the last four reads */
- if((door_history & 0b0000000000001111) == 0b0000000000000000).
- {
- TASK_Door_Handler(LOW);
- }
- else if((door_history & 0b0000000000001111) == 0b0000000000001111)
- {
- TASK_Door_Handler(HIGH);
- }
- /* Delay 1/2 second to eliminate the reciprocal interrupt (high-->low or low-->high)
- vTaskDelay(500 / portTICK_PERIOD_MS);
- gpio_intr_enable(door_sensor);
- }
- }