ESP32 interupt from continuous 10 hertz 5mS low-going pulse, never triggers

const uint8_t InterruptPin = 4;
const uint8_t OutPin = 23;
void IRAM_ATTR function_ISR() {
  digitalWrite(OutPin,HIGH);
  delay(5);
  digitalWrite(OutPin,LOW);
}
void setup() {
  pinMode(OutPin,OUTPUT);
  pinMode(InterruptPin, INPUT_PULLUP);
  attachInterrupt(InterruptPin, function_ISR, FALLING); 
  digitalWrite(OutPin,LOW);
}
void loop() {
}

Can't get the above code to ever trigger. Any help would be great. Works with a button.
Here is the setup:

pinMode(InterruptPin, INPUT);

A delay call inside an interrupt?

And shouldn't the attachInterrupt call use digitalPinToInterrupt?

attachInterrupt(digitalPinToInterrupt(InterruptPin), function_ISR, FALLING);

I haven't tried this, but how about something like:

const uint8_t InterruptPin = 4;
const uint8_t OutPin = 23;
void IRAM_ATTR function_ISR() {
  digitalWrite(OutPin, !digitalRead(InterruptPin));
}
void setup() {
  pinMode(OutPin,OUTPUT);
  pinMode(InterruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(InterruptPin), function_ISR, CHANGE); 
  digitalWrite(OutPin,LOW);
}
void loop() {
}

Thank you, I'll try it !!

Well, I tried and still no movement on the output. The attachInterrupt statement I used works with a button to pull it low.

I'll try that, I had the pull-up for the switch.

OK, I tied it, and it did not make a difference. Thanks though.

Well, I just tried my code on a FireBeetle32 and other than changing the output pin, it worked like a charm as it was.

1 Like

If you want to take a stab at kicking out delay(), pore over this --
https://randomnerdtutorials.com/esp32-pir-motion-sensor-interrupts-timers/

Are you confident that your external signal source is working as anticipated?

1 Like

It is perfect on the oscilloscope.

Well, Maybe I'll try a different Arduino. Thanks

Thank you everyone for your help.
I got it to work with a Wemos D1 Mini, not sure about the ESP32 issue.

This can be closed

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.