{"action":"created","issue":{"url":"https://api.github.com/repos/espressif/esp-idf/issues/1234","repository_url":"https://api.github.com/repos/espressif/esp-idf","labels_url":"https://api.github.com/repos/espressif/esp-idf/issues/1234/labels{/name}","comments_url":"https://api.github.com/repos/espressif/esp-idf/issues/1234/comments","events_url":"https://api.github.com/repos/espressif/esp-idf/issues/1234/events","html_url":"https://github.com/espressif/esp-idf/issues/1234","id":271638216,"number":1234,"title":"GPIO Interrupt sometimes doesn't fire?","user":{"login":"chanibal","id":697605,"avatar_url":"https://avatars0.githubusercontent.com/u/697605?v=4","gravatar_id":"","url":"https://api.github.com/users/chanibal","html_url":"https://github.com/chanibal","followers_url":"https://api.github.com/users/chanibal/followers","following_url":"https://api.github.com/users/chanibal/following{/other_user}","gists_url":"https://api.github.com/users/chanibal/gists{/gist_id}","starred_url":"https://api.github.com/users/chanibal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chanibal/subscriptions","organizations_url":"https://api.github.com/users/chanibal/orgs","repos_url":"https://api.github.com/users/chanibal/repos","events_url":"https://api.github.com/users/chanibal/events{/privacy}","received_events_url":"https://api.github.com/users/chanibal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-06T22:08:21Z","updated_at":"2017-11-06T22:50:19Z","closed_at":null,"author_association":"NONE","body":"I had issues with debouncing a simple button, I traced them down to a ISR registered by `gpio_isr_handler` are not always executing. A simple test case:\r\n\r\n```c++\r\nconst gpio_num_t pin = GPIO_NUM_34;\r\nvolatile int rise = 0;\r\nvolatile int fall = 0;\r\n\r\nextern \"C\" void IRAM_ATTR triggered_isr(void* instance) {\r\n\tif (gpio_get_level(pin)) rise++; \r\n\telse fall++;\r\n}\r\n\r\nextern \"C\" void app_main() {\r\n\tgpio_config_t config = {\r\n\t\t.pin_bit_mask = 1ull << pin,\r\n\t\t.mode = GPIO_MODE_INPUT,\r\n\t\t.pull_up_en = GPIO_PULLUP_DISABLE,\r\n\t\t.pull_down_en = GPIO_PULLDOWN_DISABLE,\r\n\t\t.intr_type = GPIO_INTR_ANYEDGE\r\n\t};\r\n\tESP_ERROR_CHECK(gpio_config(&config));\r\n\r\n\tgpio_install_isr_service(0);\r\n\tgpio_isr_handler_add(pin, triggered_isr, nullptr);\r\n\r\n\tfor (;;) {\r\n\t\tvTaskDelay(pdMS_TO_TICKS(1000));\r\n\t\tESP_LOGI(\"button-test\", \"rise=%04d, fall=%04d, diff = %04d\", rise, fall, (rise-fall));\r\n\t}\r\n}\r\n```\r\n\r\nWill yield results like:\r\n```\r\nI (10640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (11640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (12640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (13640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (14640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (15640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (16640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (17640) button-test: rise=0000, fall=0000, diff = 0000\r\nI (18640) button-test: rise=0001, fall=0002, diff = -001\r\nI (19640) button-test: rise=0002, fall=0003, diff = -001\r\nI (20640) button-test: rise=0004, fall=0004, diff = 0000\r\nI (21640) button-test: rise=0005, fall=0006, diff = -001\r\nI (22640) button-test: rise=0007, fall=0007, diff = 0000\r\nI (23640) button-test: rise=0008, fall=0009, diff = -001\r\nI (24640) button-test: rise=0010, fall=0011, diff = -001\r\nI (25640) button-test: rise=0014, fall=0014, diff = 0000\r\nI (26640) button-test: rise=0017, fall=0019, diff = -002\r\nI (27640) button-test: rise=0020, fall=0021, diff = -001\r\nI (28640) button-test: rise=0028, fall=0029, diff = -001\r\nI (29640) button-test: rise=0034, fall=0037, diff = -003\r\nI (30640) button-test: rise=0040, fall=0043, diff = -003\r\nI (31640) button-test: rise=0043, fall=0046, diff = -003\r\nI (32640) button-test: rise=0045, fall=0049, diff = -004\r\nI (33640) button-test: rise=0049, fall=0052, diff = -003\r\n```\r\n\r\nAm I using interrupts correctly? Is one interrupt hiding another that is quick in succession? If so, how can I prevent this?\r\n\r\nI have tried `std::atomic<int>` but it did not help."},"comment":{"url":"https://api.github.com/repos/espressif/esp-idf/issues/comments/342314774","html_url":"https://github.com/espressif/esp-idf/issues/1234#issuecomment-342314774","issue_url":"https://api.github.com/repos/espressif/esp-idf/issues/1234","id":342314774,"user":{"login":"chanibal","id":697605,"avatar_url":"https://avatars0.githubusercontent.com/u/697605?v=4","gravatar_id":"","url":"https://api.github.com/users/chanibal","html_url":"https://github.com/chanibal","followers_url":"https://api.github.com/users/chanibal/followers","following_url":"https://api.github.com/users/chanibal/following{/other_user}","gists_url":"https://api.github.com/users/chanibal/gists{/gist_id}","starred_url":"https://api.github.com/users/chanibal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chanibal/subscriptions","organizations_url":"https://api.github.com/users/chanibal/orgs","repos_url":"https://api.github.com/users/chanibal/repos","events_url":"https://api.github.com/users/chanibal/events{/privacy}","received_events_url":"https://api.github.com/users/chanibal/received_events","type":"User","site_admin":false},"created_at":"2017-11-06T22:50:19Z","updated_at":"2017-11-06T22:50:19Z","author_association":"NONE","body":"If by hw filter, you mean a capacitor then this happens even more with one.\r\n\r\nI updated the solution to use level interrupts, to be exact:\r\n```C++\r\nextern \"C\" void IRAM_ATTR triggered_isr(void* instance) {\r\n\tif (gpio_get_level(pin)) {\r\n\t\tgpio_set_intr_type(pin, GPIO_INTR_LOW_LEVEL);\r\n\t\trise++;\r\n\t}\r\n\telse {\r\n\t\tgpio_set_intr_type(pin, GPIO_INTR_HIGH_LEVEL);\r\n\t\tfall++;\r\n\t}\r\n}\r\n// ...\r\n\t\t.intr_type = GPIO_INTR_LOW_LEVEL\r\n```\r\n\r\nBut this still fails (although, I need to try harder to break it):\r\n```\r\nI (1720) button-test: rise=0000, fall=0000, diff = 0000\r\nI (2720) button-test: rise=0000, fall=0000, diff = 0000\r\nI (3720) button-test: rise=0000, fall=0001, diff = -001\r\nI (4720) button-test: rise=0001, fall=0001, diff = 0000\r\nI (5720) button-test: rise=0001, fall=0001, diff = 0000\r\nI (6720) button-test: rise=0003, fall=0003, diff = 0000\r\nI (7720) button-test: rise=0008, fall=0008, diff = 0000\r\nI (8720) button-test: rise=0010, fall=0011, diff = -001\r\nI (9720) button-test: rise=0011, fall=0011, diff = 0000\r\nI (10720) button-test: rise=0011, fall=0011, diff = 0000\r\nI (11720) button-test: rise=0011, fall=0011, diff = 0000\r\nI (12720) button-test: rise=0011, fall=0012, diff = -001\r\nI (13720) button-test: rise=0012, fall=0012, diff = 0000\r\nI (14720) button-test: rise=0012, fall=0012, diff = 0000\r\nI (15720) button-test: rise=0013, fall=0014, diff = -001\r\nI (16720) button-test: rise=0018, fall=0019, diff = -001\r\nI (17720) button-test: rise=0023, fall=0025, diff = -002\r\nI (18720) button-test: rise=0031, fall=0033, diff = -002\r\nI (19720) button-test: rise=0039, fall=0040, diff = -001\r\nI (20720) button-test: rise=0046, fall=0048, diff = -002\r\nI (21720) button-test: rise=0053, fall=0055, diff = -002\r\nI (22720) button-test: rise=0061, fall=0063, diff = -002\r\nI (23720) button-test: rise=0066, fall=0072, diff = -006\r\nI (24720) button-test: rise=0066, fall=0072, diff = -006\r\nI (25720) button-test: rise=0066, fall=0072, diff = -006\r\nI (26720) button-test: rise=0066, fall=0072, diff = -006\r\n```\r\n\r\nI guess that the issue is in one of:\r\n* `gpio_get_level` - is there a better way to check what triggered the ISR?\r\n* `gpio_set_intr_type` - is it OK to call this from ISR context?\r\n* `rise++` - probably not atomic enough (again, tried with std::atomic, but did not help - does it even work on ESP32?)"}}
{"actor":{"display_login":"chanibal"}}