I was using a NodeMCU a little while ago, but now that I've come back to it, any time I try to set up an interrupt in the arduino IDE I get the error "ISR not in IRAM".
Could anyone point me in the right direction of how to define/setup my ISRs?
I experienced the same issue on previously working code after updating to version 2.5.1 of the ESP8266 library. I was able to get around it by reverting back to 2.5.0.
Don't know if it's a bug in the update, or something that shouldn't have been allowed all along. I suspect it's a bug in the update.
MechScientist:
I experienced the same issue on previously working code after updating to version 2.5.1 of the ESP8266 library. I was able to get around it by reverting back to 2.5.0.
Don't know if it's a bug in the update, or something that shouldn't have been allowed all along. I suspect it's a bug in the update.
I experienced the same issue and resolved the same way : downgrade to v2.5.0
MechScientist:
Don't know if it's a bug in the update, or something that shouldn't have been allowed all along.
I've ran into the same issue... and it's actually something that we shouldn't have been allowed all along. A quick explanation here.
The proper way to do an ISR for ESP8266 is by placing it in the IRAM - instead of having it execute from Flash. The second option works most of the time but is not reliable, a few years ago I found that out the hard way as I had an ISR crash now and then. Adding the ICACHE_RAM_ATTR fixed this issue: it places the ISR in IRAM, and no more random crashes.
The new 2.5.2 core just enforces this more strictly.
void ISRoutine () {
int value;
Serial.println("I am in ISR");
value = digitalRead(pin4);
Serial.print("Value read = ");
Serial.println(value);
digitalWrite(LED_BUILTIN,!value);
}
Can someone explain how to revert back to version 2.5.0 - in baby steps because I can't seem to get it right!
Please!!
MechScientist:
I experienced the same issue on previously working code after updating to version 2.5.1 of the ESP8266 library. I was able to get around it by reverting back to 2.5.0.
Don't know if it's a bug in the update, or something that shouldn't have been allowed all along. I suspect it's a bug in the update.
void ISRoutine () {
int value;
Serial.println("I am in ISR");
value = digitalRead(pin4);
Serial.print("Value read = ");
Serial.println(value);
digitalWrite(LED_BUILTIN,!value);
}
I used this approach surgested by Hitanjali, and it made the trick for me.
I assume this is the right way to ensure ISR is placed in IRAM!?!
Comments are welcome.
Thanks
hitanjali:
I was also facing the same issue. But following code example would solve your issue.
/* This code is for executing the interrupt in ESP8266.
The main purpose is to solve the ISR not in RAM isssue.
ISR Function : The interrupt pin [GPIO5 ] once changes state from HIGH to LOW
ISR reads the value on GPIO4 and changes the state of the BUILTIN led based on the value read
*/
void ISRoutine () {
int value;
Serial.println("I am in ISR");
value = digitalRead(pin4);
Serial.print("Value read = ");
Serial.println(value);
digitalWrite(LED_BUILTIN,!value);
}
rmoggia:
HI. Tell me please why is a bad idea.
Thanks
Serial uses interrupts in the background to send/receive bytes as well as internal buffers to hold said bytes. During an ISR, interrupts are off so nothing will actually be sent/received, only transferred to the internal buffer in preparation for transmission.
If that buffer is full, the print() function will wait for it to empty enough to add the new data to the buffer but since interrupts are off, the buffer will never decrease and you end up in an infinite wait loop.
That is how it is done on avr chips, not sure if all this applies to the ESP8266