-
Notifications
You must be signed in to change notification settings - Fork 13.3k
AttachInterrupt random crashes #1403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Update: client.connect("api.thingspeak.com", 80); or at: client.print(header + datastr); Here is the output I get from my sketch (measured data + timestamp). In this case the exception happened at client.connect() because the '0' gets printed after that. -30.00 @gmt 21:03:11.492 ctx: sys
ets Jan 8 2013,rst cause:2, boot mode:(1,7) ets Jan 8 2013,rst cause:4, boot mode:(1,7) wdt reset it does actually not reset here, just hangs... |
Is there delay in ISR ? |
The illegal instruction exception (exception cause 0) with an 0x402xxxxx
address suggests you might be calling a function in flash from an interrupt
handler. What's at address 0x402021d4 (value of epc1)? Check in an
objdump. Move that function and anything it calls to RAM with
ICACHE_RAM_ATTR .
|
Thank you for the hint, I am unfamiliar with decyphering the exception dump info. I will take a stab at the objdump to get to the root of it. |
Here is what I found (it is not much):
Here is what I get:
.etc. checking the objdump at 0x40202058 I find parts of the interrupt vector:
What are the options? Sorry, I am totally lost. |
this may be rlated to #797 and/or #1020 I see mentioned that putting ICACHE_RAM_ATTR does not work. Mentioned by Igrr: #797 (comment) Bonus question: if a function is called from the interrupt, does that function also have to have the ICACHE_RAM_ATTR or is this done by the compiler? Or is it better to inline the functions called from the interrupt? |
The interrupt handler and everything it might call into need to be in RAM.
You can verify whether the attribute worked by running objdump again;
functions in RAM will have addresses like 0x401xxxxx.
|
Thank you so much, it looks like that did the trick. |
hi, Thaks |
very easy, just put it int front of your function name. Be aware that all functions called within an interrupt function must reside in ram, not only the function itself.
|
So if I use the Wire library inside the interrupt does this mean I need to make a modified version of Wire that uses ICACHE_RAM_ATTR in front of the function names? |
Alternatively, you can disable this interrupt while reading/writing/erasing flash memory. This includes EEPROM, SPIFFS, and WiFi configuration functions. |
Interesting, did not know that the flash access is the reason for this, I thought it's a general requirement for this processor architecture. @mkeyno what do you mean by tutorial? it is as simple as putting one keyword in front of your function. I put an example of it above. Inside the interrupt do not call any other functions (except inline functions maybe). I used it here: |
Is it possible that there is an issue using the AttachInterrupt function?
I have a setup where I attach a pin to an external signal that triggers approximately every 20ms. In parallel I send data to a server (Thingspeak) every 15 seconds. I get random crashes always at the point where data needs to be sent out. If I deactivate the updates to the server, everything runs smoothly. The crashes happen at random times, sometimes after just one minute, sometimes after 30 minutes or even longer.
Any explanation for this behaviour?
The interrupt shoud be fairly short, it does some calculations but no loops.
The text was updated successfully, but these errors were encountered: