-->
Page 1 of 2

ESP8266 interrupt and ISR not in IRAM!

PostPosted: Sat Aug 10, 2019 1:10 pm
by xorcz
Hi, I used the code https://techtutorialsx.com/2016/12/11/e ... nterrupts/
added ICACHE_RAM_ATTR, but I am still receiving errors. What more should I fix?
ESP-12F with 8MB, Arduino 1.8.9 and board library 2.5.2 installed.

Code:

Code: Select all#define ICACHE_RAM_ATTR
const byte interruptPin = 13;
volatile byte interruptCounter = 0;
int numberOfInterrupts = 0;
 
void setup() {
 
  Serial.begin(115200);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, RISING);
 
}
 
void ICACHE_RAM_ATTR handleInterrupt() {
  interruptCounter++;
}
 
void loop() {
 
  if(interruptCounter>0){
 
      interruptCounter--;
      numberOfInterrupts++;
 
      Serial.print("An interrupt has occurred. Total: ");
      Serial.println(numberOfInterrupts);
  }
 
}

Error:
Code: Select all20:08:22.329 -> Abort called
20:08:22.329 ->
20:08:22.329 -> >>>stack>>>
20:08:22.329 ->
20:08:22.329 -> ctx: cont
20:08:22.329 -> sp: 3ffffdb0 end: 3fffffc0 offset: 01b0
20:08:22.329 -> 3fffff60:  feefeffe 00000001 3ffee26c 3ffee2c4 
20:08:22.329 -> 3fffff70:  3fffdad0 00000001 3ffee26c 3ffee2c4 
20:08:22.329 -> 3fffff80:  3fffdad0 00000000 3ffee294 401003da 
20:08:22.329 -> 3fffff90:  feefeffe 00000000 3ffee294 40201069 
20:08:22.329 -> 3fffffa0:  feefeffe feefeffe feefeffe 402018b4 
20:08:22.329 -> 3fffffb0:  feefeffe feefeffe 3ffe84f4 401006c5 
20:08:22.329 -> <<<stack<<<
20:08:22.373 ->
20:08:22.373 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
20:08:22.373 ->
20:08:22.373 -> load 0x4010f000, len 1384, room 16
20:08:22.373 -> tail 8
20:08:22.373 -> chksum 0x2d
20:08:22.373 -> csum 0x2d
20:08:22.373 -> v8b899c12
20:08:22.373 -> ~ld
20:08:22.431 -> ISR not in IRAM!


Thanks

Re: ESP8266 interrupt and ISR not in IRAM!

PostPosted: Mon Aug 12, 2019 3:58 am
by btidey
Why have you got the line?

#define ICACHE_RAM_ATTR

That would seem to defeat adding the attribute to the ISR.

Re: ESP8266 interrupt and ISR not in IRAM!

PostPosted: Tue Aug 13, 2019 3:01 am
by xorcz
Because it does not compile without it. If the line "#define ICACHE_RAM_ATTR" is missing, the Arduino says the handleInterrupt is not declared.

I seems the same issue was answered here https://www.reddit.com/r/esp8266/commen ... nterrupts/

so I will remove #define and add
"void ICACHE_RAM_ATTR handleInterrupt();" at the very top.

Thank you

Re: ESP8266 interrupt and ISR not in IRAM!

PostPosted: Tue Aug 13, 2019 1:56 pm
by xorcz
Because it did not compile without it. I have found probably correct solution
https://www.reddit.com/r/esp8266/commen ... nterrupts/

put
void ICACHE_RAM_ATTR handleInterrupt();
to the top. It compiles now, I will test if it does not crash.