Error ISR not in IRAM!

There are two ways to handle the ISR not in IRAM issue. These examples assume that your interrupt handling function is called MyInterruptHandler

You can simply add a pre-declaration of the ISR handler routine with ICACHE_RAM_ATTR before the interrupt handler name, like this:

void ICACHE_RAM_ATTR MyInterruptHandler();

This pre-declaration of the ISR handler should be near the top of your code, before void setup - where you initialise your interrupt like this:

attachInterrupt(digitalPinToInterrupt(5),MyInterruptHandler,FALLING);

your interrupt handler would then look like this:

 void MyInterruptHandler()
{
  // do your interrupt handling stuff in here....
}

Alternatively, you can skip the pre-declaration and do it in the ISR handler like this:

 void ICACHE_RAM_ATTR MyInterruptHandler()
{
  // do your interrupt handling stuff in here....
}

When you take this approach, your ISR handler MUST appear before your void loop in the sketch, otherwise you’ll get a “not declared in this scope” error when you compile the code (at least when using the Arduino IDE).

Pete.

3 Likes