I have configured two external interrupts on my Mega2560, specifically on pins 2 and 3, both set to trigger on a falling edge. Pin 3 has an external pull-up resistor with a voltage of 5V and should maintain a high output level constantly. Pin 2 is continuously outputting high and low levels at a frequency of 10Hz through another microcontroller. For some unknown reason, the interrupt on pin 3 is triggered roughly once every 1 to 10 hours. I have clearly pulled it up to 5V with a pull-up resistor, so why is the interrupt still being triggered?
Perhaps you may ask why I don't simply disable the interrupt on pin 3 since my program only uses the interrupt on pin 2. In response to this, I want to clarify that I have simplified the issue encountered in my actual project into this format. Initially, I suspected it could be due to other problems, but even in this simplified form, the issue persists. In my actual project, pin 3 is also being triggered inexplicably.
I have already tried replacing the Mega2560 development board and the wires, but the issue remains. I hope you can provide some advice. Thank you very much for your help. I
will post my code for everyone to review.
Here is my wiring diagram, which includes a common ground connection. MCU2 sends high and low level signals at a frequency of 10HZ. The blue one on the left is MCU2. MCU1 is the green one on the right. When a falling edge occurs, it triggers an external interrupt on pin 2 every 100ms. Pin 3 should not be triggered, as I have configured it with an internal pullup resistor.
Wiring:MCU1-GND—MCU2-GND MCU1-PIN 2—MCU2-PIN 2
The later update
2024-12-2
I tried replacing the ESP32 to test this scenario.
I changed the Arduino version from 2.3 ->1.8.
I used twisted pair cables, shortened and replaced the wires.
I switched from external pullup to internal pullup.
I stopped using Serial.print inside interrupts.
After trying these five methods, the issue still persists.
The latest update 2024-12-3 The problem has been solved. It was an issue with the USB port power supply. Thank you all very much for your help.
Thank you for your reply. I have handled the common ground connection, and the wires I used are Dupont wires. However, I have already ruled out the possibility of issues with the wires.
I apologize for only being able to reply to your message now. Yes, I am using a breadboard. Regarding crosstalk issues, I'm not sure, but I think this circuit is very simple and should be stable. I am using a 9.1k resistor. I will upload my circuit diagram later. Thank you very much.
thank you for your reply. I haven't tried using the internal pull-up resistor yet, because my project requires the use of an external pull-up. However, I will try using the internal pull-up to test it and let you know the result. Thank you very much.
Thank you for your reply. Oh, is that so? Sorry, I'm still new to Arduino. During my learning process, I found quite a few people using Serial.print in interrupts for easier debugging. I will try it later and let you know the result. Thank you.
Thank you for your reply! I will try to avoid performing serial input/output operations within interrupts, and I'll upload a photo of my setup. However, I've seen many demos that support printing within ISRs, which is a bit confusing to me.
Of course you have encountered some very poor coding examples on the web.
As @J-M-L and I pointed out, with some Arduinos, a workaround was put in place so that beginners, who have little to no idea how these things work, could get away with such bad practice.
However, the workaround supports Serial.print only, and not I2C or other serial protocols.
There are lots of non-obvious rules and gotchas (which can lead to serious errors) to do with implementing interrupts. And, there aren't many occasions where the return is actually worth the effort required to implement them.
For many projects, monitoring an input pin by polling is much simpler, more reliable and sometimes even faster than using interrupts.
Great approach. I've also tried using a perfboard for soldering instead of a breadboard, but the error still occurred. Today, it happened again after nine hours of work. It's really frustrating, and I suspect it might be an issue with the board. I even tried switching to an Uno, but the same problem persists...