ESP32 - interrupt handling issue.

TibiToz
Posts: 7
Joined: Mon Aug 10, 2020 1:46 pm

ESP32 - interrupt handling issue.

Postby TibiToz » Mon Aug 10, 2020 2:10 pm

Hi,

I'm quite new to C and the embedded world, i'm trying to do an interrupt on GPIO36 and GPIO39 (these pins can't be changed). I hardware pull high both of the pins with a 10k Resistance.

I used the ESP-IDF example :

Here is my initialisation :
  1. #define RESET_BUTTON_0      GPIO_NUM_36
  2. #define RESET_BUTTON_1      GPIO_NUM_39
  3. #define GPIO_BUTTON_MASK    ((1ULL<<RESET_BUTTON_0) | (1ULL<<RESET_BUTTON_1))
  4.  
  5. uint64_t button_down;  // store the esp_time
  6. uint8_t RESET_SECONDS = 10; // Number of seconds to push down RESET_BUTTON for a factory reset
  7.  
  8. static xQueueHandle gpio_evt_queue = NULL;
  9.  
  10. void IRAM_ATTR button_isr_handler(void* arg) {
  11.    
  12.     uint32_t gpio_num = (uint32_t) arg;
  13.     xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
  14.  
  15. }
  16.  
  17. void gpio_output_conf(){
  18.  
  19.     gpio_config_t io_conf;
  20.  
  21.     //interrupt of rising edge
  22.     io_conf.intr_type = GPIO_INTR_ANYEDGE;
  23.     //bit mask of the pins,
  24.     io_conf.pin_bit_mask = GPIO_BUTTON_MASK;
  25.     //set as input mode    
  26.     io_conf.mode = GPIO_MODE_INPUT;
  27.     // PIN 34-39 dont have pull up or pull down by software
  28.     io_conf.pull_down_en = 0;
  29.     //enable pull-up mode
  30.     io_conf.pull_up_en = 0;
  31.     gpio_config(&io_conf);
  32. }
Here is my Button task wich is a factory reset task if the GPIO36 is held more then 10secs
[/Codebox]
  1. void reset_task(void *pvParamater){
  2.    
  3.     uint32_t io_num;
  4.    
  5.     while(1){
  6.        
  7.        
  8.         if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
  9.             printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
  10.            
  11.             if(gpio_get_level(RESET_BUTTON_0) == 1) {
  12.  
  13.                 button_down = esp_timer_get_time ();
  14.                
  15.             }
  16.        
  17.             else {
  18.  
  19.                     // button released, verifiy down time
  20.                 if((esp_timer_get_time() - button_down) > RESET_SECONDS * 1000 * 1000){
  21.                     printf("Reset button was pressed for more than %d seconds, loading factory firmware...\n,",
  22.                                         RESET_SECONDS);
  23.                
  24.                     //search the factory partition in flash memory
  25.  
  26.                     esp_partition_iterator_t pi = esp_partition_find(ESP_PARTITION_TYPE_APP,
  27.                                         ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
  28.  
  29.                     // if partition is found, set it to boot partition and reset the chip
  30.                     if (pi != NULL) {
  31.  
  32.                         const esp_partition_t* factory = esp_partition_get(pi);
  33.                         esp_partition_iterator_release(pi);
  34.                         if(esp_ota_set_boot_partition(factory) == ESP_OK) esp_restart();
  35.  
  36.                     }
  37.  
  38.                 else
  39.                 {
  40.                      printf("Factory partition not found !\n");
  41.                 }
  42.                
  43.             }
  44.         }
  45.     }
  46.  
  47. }
  48. }
And here is my main :
  1. void app_main() {
  2.    
  3.    
  4.     gpio_output_conf();
  5.  
  6.     gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
  7.  
  8.     xTaskCreate(reset_task, "reset_task", 8192, NULL, 5, NULL);
  9.    
  10.     // install ISR and add handler
  11.     gpio_install_isr_service(0);
  12.     gpio_isr_handler_add(RESET_BUTTON_0, button_isr_handler,(void*) RESET_BUTTON_0);
  13.     gpio_isr_handler_add(RESET_BUTTON_1, button_isr_handler,(void*) RESET_BUTTON_1);       
  14.  
  15. }
My problem is : When the button is not pressed (PULLUP) the interrupt is flowing, when the button is pressed (PULLDOWN) only 10 triggers are happening, i need to do exactly the opposite, because if only 10 triggers at 0lvl are happening it is not enough time to trigger the factory reset.

I need to trigger the interrupts when the lvl is at 0. not 1.

Thank you for your time,

Tibi

ESP_Sprite
Posts: 9711
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 - interrupt handling issue.

Postby ESP_Sprite » Tue Aug 11, 2020 11:10 am

What do you mean with 'flowing'? Only 10 triggers happening when you press the button is to be expected. In an ideal world, you would see only one interrupt (as there's only one high->low change) but in the real world, buttons 'bounce' so you see more edges; 10 sounds like a possible amount there.

Who is online

Users browsing this forum: No registered users and 78 guests