-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP32 INTERRUPT ON BOTH FALLING AND RISING EDGE #1111
Comments
I am using an interrupt on io34 and having the same issue; I have a 10K resistor pulling it high to try to stabilized it. It seems to show the same behavior whether FALLING or RISING is used. Sometimes interrupt occurs on the falling edge and other times it occurs on the rising edge and switches back every few seconds. |
actually its working on change no matter which mode is selected... |
i am having interrupts both on falling and rising edge .........how to resolve that problem related to gpio |
i also have the same problem. I am using an interrupt on pin 27, i tried using FALLING and RISING but it seems that the ISR got trigger on CHANGE. are there any solution to this problem? |
i have check using esp-idf gpio code that is working fine for positive edge trigger....but not working in arduino............ |
#include "driver/gpio.h" #define GPIO_OUTPUT_IO_0 18 static xQueueHandle gpio_evt_queue = NULL; static void IRAM_ATTR gpio_isr_handler(void* arg) } void setup() Serial.begin(115200);
} } |
working in this way |
yes it was the problem...however i had solved it earlier
…On Wed, Jul 4, 2018 at 10:32 PM, musskopf ***@***.***> wrote:
I can confirm the issue is happening to me as well. My test code looks
like:
// User Buttons
#define USER_BT1 25
/* * Interrupt Definitions */volatile uint8_t bt1Pressed = 0;
void bt1IntHandler()
{
bt1Pressed++;
}
void setup() {
Serial.begin(115200);
Serial.println("Starting Up");
Serial.println(" - User Buttons");
pinMode(USER_BT1, INPUT_PULLUP);
// Some Delay for things to calm down
delay(30);
// Add Interrupts
attachInterrupt(digitalPinToInterrupt(USER_BT1), bt1IntHandler, FALLING);
}
void loop() {
// Print the number of interrupts every 3 second
Serial.print("Number of Interrupts: ");
Serial.println(bt1Pressed);
delay(3000);
}
I also capture the button press on my scope, no noise in the signal.
[image: ds1104z_ds1za180300224_2018-07-05_15 23 06]
<https://user-images.githubusercontent.com/13247713/42304141-1f4f92f4-8068-11e8-8da2-3000ecfc8da8.png>
The output on the Serial Print always increment by "2" every time I press
the button. If I press and hold, it increments 1, but it'll increment 1
again once I release it.
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13256
entry 0x40078a90
Starting Up
- User Buttons
Number of Interrupts: 0
Number of Interrupts: 2 <- Quick Press and Release
Number of Interrupts: 4 <- Another Press and Release
Number of Interrupts: 5 <- Press and Hold
Number of Interrupts: 5 <- Still holding
Number of Interrupts: 6 <- Released
Number of Interrupts: 6
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1111 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ad_cUN5dOE05wNarZgH7Uf_lfnwgnoj0ks5uDaT-gaJpZM4SE50e>
.
|
try this code #include "driver/gpio.h" #define GPIO_OUTPUT_IO_0 18 static xQueueHandle gpio_evt_queue = NULL; static void IRAM_ATTR gpio_isr_handler(void* arg) } void setup() Serial.begin(115200); gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); int cnt = 0; } |
attach interrupt function is not working as expected |
Yes, I saw it, many thanks! In any case, I was highlighting that this still a problem with the Arduino "attachInterrupt" function. |
I had a similar problem that turned out to be noise on the interrupt input line. I think it was resolved with a .1uF capacitor.
On Thursday, July 5, 2018, 7:42:24 AM EDT, usmanshahid001 <[email protected]> wrote:
attach interrupt function is not working as expected
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Just to be clear this happens with the ESPIF libraries too. Not just the Arduino attachInterrupt() function. Using the same board that @musskopf provided images for above and the following:
The trigger fires when it is depressed and then once again when it is released. As you can see from the screenshots from @musskopf the signal is clean. |
@william-ferguson-au If the interrupt is allocated to a shared interrupt it only act as a level interrupt. This design choice is required because because of the interrupt latency of sharing an interrupt. The ISR has to do the filtering. Currently pin interrupt routine assumes the hardware will filter base on selection (FALLING, RISING, LOW, HIGH, CHANGE). I assume(ass u me) that the code has been tested in a single interrupt(non Shared) environment. On a non shared interrupt it will correctly respond. I ran into the same problem when I was building the I2C ISR. if(!i2c->intr_handle) { // create ISR for either peripheral
// log_i("create ISR %d",i2c->num);
uint32_t ret = 0;
uint32_t flags = ESP_INTR_FLAG_EDGE | //< Edge-triggered interrupt
ESP_INTR_FLAG_IRAM | //< ISR can be called if cache is disabled
ESP_INTR_FLAG_LOWMED; //< Low and medium prio interrupts. These can be handled in C.
if(i2c->num) {
ret = esp_intr_alloc_intrstatus(ETS_I2C_EXT1_INTR_SOURCE, flags, (uint32_t)&i2c->dev->int_status.val, 0x1FFF, &i2c_isr_handler_default,i2c, &i2c->intr_handle);
} else {
ret = esp_intr_alloc_intrstatus(ETS_I2C_EXT0_INTR_SOURCE, flags, (uint32_t)&i2c->dev->int_status.val, 0x1FFF, &i2c_isr_handler_default,i2c, &i2c->intr_handle);
}
I think the Pin interrupt ISR need to be rewritten. I have not needed it yet. Chuck. |
Note also, that it also fires twice if I use |
@stickbreaker when you say "shared" interrupt, what do you mean? I do want to have interrupts for several pins, but I am getting this behaviour when I have only configured an interrupt for a single pin. |
@stickbreaker I read http://esp-idf.readthedocs.io/en/latest/api-reference/system/intr_alloc.html and am now confused. By using:
am I somehow using a shared interrupt? If so, how do I define interrupts for 3 buttons that only fire only the falling edge? |
@william-ferguson-au I'm not able to answer you questions. I have not studied interrupts exhaustively. I just learned enough to solve my problems. To solve your problem you are going to have to delve deeper into the hardware and the ESP interrupt allocation code. I believe that issues revolve around interrupt source assignment and shared interrupt filtering. Through a quick(non authoritarian review) I surmise that all pin interrupt sources use one interrupt(shared) and either the pin source configuration is wrong, or my understanding is bogus. This link describes the hardware GPIO interface: This is the part of the GPIO structure that I think relates to interrupt configuration. I think the current GPIO interrupt functions are not correct, but I have not had the need to fix them. Have a Go. Chuck. |
Same problem here. |
same problem using ESP32 Wroom 32u only falling edge works for me , if i select rising edge it triggers on both rising and falling , no noise on input as i have 100nf there. |
On further testing what i found is weird but it solves this double trigger issue with ESP32 |
The info is perfect. You can use the internal pullup resistor using:
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
My experience:
I had never a problem with an interrupt using the ESP32. Maybe you want to look at: There you can find the measurements for external interrupts. |
Have there been any updates on this issue? I have studied this issue closely and it appears that when in rising or falling mode the ISRs trigger randomly in the other mode. (This is not a key bounce issue as have been discussed above. This is a test square wave fed directly to the MCU) In the image below, the yellow square wave is fed into PIN 17 on the ESP32. Each time the ISR fires, it toggles the output pin shown in purple. To the left you can see that the ISR fired on the rising edge of the input, however in the following two pulses it fired correctly. The ISR setup and code follows:#define RPM_PIN 17
void IRAM_ATTR RPM_ISR()
// ESP 32 appears to have a bug where sometimes different edges fire regardless of rising/falling
} // RPM_ISR |
I have seen this same comment from several different people, and the only thing in common that everyone has had that I noticed was that they are all using INPUT_PULLUP. I wonder if the ESP32 disconnects the pin internally during some part of the interrupt process and reconnecting it sometimes retriggers the interrupt. Unlike traditional microcontrollers where you have to manually clear an interrupt flag, that doesn't seem to be the case with the ESP32. Is that true? |
ESP32 does not require clearing the interrupt pending flag (or at least if it does this is done in background). I will try an external pull up to see if that helps. Some posts are about key-bounce which is clearly not what is happening here. It does seem like a noise problem. A previous post suggested that using the IDF instead of Arduino FW creates code that works correctly. I try to stick with Arduino since I write for so many different CPUs. Thanks for the feedback Jim, I'll run some tests and let you know what I find out. |
@DougArmstrong - have you made any discoveries regarding internal vs external pullups? And, in your scope shot - is the yellow trace being probed right at the ESP32 input pin, or is there some additional wire length or passive components between the scope probe and the GPIO pin? The scope shot certainly does look like a clean and fast-edged signal. |
Random interrupts happen on ‘input only’ pins 34-39 that are pulled up or stay high. It has nothing to do with EMI. |
Similar to the OP, I had a clean signal, but experienced My interrupts were originally configured as follows: pinMode(21, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(21), isr_1, FALLING);
pinMode(14, INPUT);
attachInterrupt(digitalPinToInterrupt(14), isr_2, RISING); After reading @stickbreaker 's comment...
I configured the interrupts to fire on the same edge, and I was able to resolve my issue. pinMode(21, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(21), isr_1, RISING);
pinMode(14, INPUT);
attachInterrupt(digitalPinToInterrupt(14), isr_2, RISING); Minimally, it appears to be a bug in the Arduino Board Package implementation.
|
ESP32 is really a "fake cpu".
I use a PIC16C54 at 1997 and the interrupts works fine. Now, at 2021, It's unbelievable that a CPU has serious problems interrupting a GPIO. Its the fantastic ESP32. And there is no easy workaround . |
This issue is still occurring for me, specifically on GPIO 35 (which is input only and has no pull up / pull down). I'm setting the config for GPIO 0 and GPIO 35 at the same time, so they are identical, but GPIO 0 behaves as expected and reacts on falling edge only while GPIO 35 will randomly interrupt on rising edges as well. Not sure if this is a hardware thing or a software thing or what. I did consider adding a pull up resistor to the pin, but it seems that GPIO_INTR_ANYEDGE works as expected on both GPIO 0 and GPIO 35. This being the case, I was able to work around the issue by just triggering on all edges and implementing the falling edge detector in software. Just keep track of the previous input state - when an edge event happens, check the previous state for that input. If the previous state was high and the new state is low, then you have a falling edge. In theory, you could just check inside your ISR whether or not the pin is now low or now high as suggested by @n6il in the linked issue, but this wasn't working for me for some reason.
|
@LMBernardo I also had difficulties when trying to use RISING and FALLING edges simultaneously. Once I set my logic to use only RISING or FALLING, then the interrupts behaved as expected. See: #1111 (comment) |
I faced the same issue with a signal from an optoisolator. The unexpected interrupts happened due to a significant rise/fall time. The ESP32 does not work well with curved edges. It needs straight edges to avoid the unexpected interrupts. There's multiple ways to handle/avoid this issue:
|
Hi, I am experience the same problem.
This produces an interrupt as expected if the signal is applied for a short time. |
The core panicking can happen because while the signal stays high, the interrupt keeps triggering? |
There is no Schmitt triggering on ESP32 inputs, interrupts on this MPU need a quick clean transition. It's best to use an external Schmitt trigger buffer. The STM32 series of MPU's have Schmitt on all inputs which make them a lot more robust, so I'll often interface less than ideal inputs with a Black-Pill and then send the data on to the esp32, works out cheaper than using external Schmitt buffers !
|
falling edge and rising edge ramp should be vertical. there should be no capacitor. solution code for FALLING edge: |
Hiii i am using proximity sensor with esp32 and it is calling ISR routine on both Falling and Rising Edge
i have verified it using nodemcu which is working properly i have tried all things like Falling Rising Change HIGH but its showing the same behaviour kindly help me in this regard...
The text was updated successfully, but these errors were encountered: