1

I am using the ESP32 dev board with the Arduino and wish to use an interrupt to determine if a master device has sent the Slave Select flag to the ESP32.

Here is what I've tried so far

1)

#define SS 34

void enableSend() {
    Serial.println("SS Enabled");
}

void setup(){
  pinMode(SS, INPUT);
  attachInterrupt(digitalPinToInterrupt(SS), enableSend, RISING);
}

2)

#define SS 34

void IRAM_ATTR enableSend() {
    Serial.println("SS Enabled");
}

void setup(){
  pinMode(SS, INPUT);
  attachInterrupt(digitalPinToInterrupt(SS), enableSend, RISING);
}

I've used both versions without digitalPinToInterrupt.

What do I need to do to get the interrupts to work? Currently, the enableSend function does not get called when pin 34 is set to high.

If it helps, here is the pinout for the ESP dev bord that I have.

6
  • what is handleInterrupt? Commented Jan 26, 2020 at 18:46
  • @Juraj Sorry! That was meant to be 'enableSend'. I forgot I modified that before posting. Updated! Commented Jan 26, 2020 at 18:47
  • copy the exact error message here. everything in interrupt handler must be in IRAM. I doubt Serial.println is in IRAM. Commented Jan 26, 2020 at 18:53
  • @Juraj There is no error. It just doesn’t run. I’ve also made a HTTP get request which works in loop() but not in the interrupt so not sure if that’s the issue. Commented Jan 26, 2020 at 18:56
  • @Juraj Also updated the title as it was misleading due to fixing one issue before I hit submit. Commented Jan 26, 2020 at 19:01

1 Answer 1

3

You definitely need the IRAM_ATTR (see 2) in order to place the ISR (interrupt service routine) in the Internal RAM (IRAM) of the ESP32.

I think that the Serial.println("SS Enabled"); that you wish to execute in the ISR is too complex for an ISR.

The ESP32 stops the regular execution flow to execute the ISR, which is supposed to be executable in minimal time, only a few CPU instructions.

Sending data over the Serial Port takes quite a few milliseconds, which is too long for an ISR.

You can use the ISR to change a variable / flag that you evaluate within the regular flow of execution, that way you minimize the risk of messing up the devices flow of execution... you can send the "SS Enabled" from there.

Sign up to request clarification or add additional context in comments.

1 Comment

I think that's it. I was also doing a HTTP request which kept crashing the device. By using the interrupts to set flags which is read my the main loop, that fixed the issue. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.