Hello,
I have a project to manage the windows (open / close) of my greenhouse. I use GPS time, temperature , rain , wind sensor, the day in the season, the time , logging info to display, SD card and Ethernet.
That's a big sketch with more then 1000 lines.
I start this project three years ago and upgrade it during my spare time during winter.
Now I have intermittent hang. I added some trace to try to approach the code which was giving this hang.
I narrowed my code to around 50 lines, which could reproduce the problem.
The purpose was to have a 1 sec interrupt to display ( on LCD 16*2) the time at the second level, and also each 2,5 sec read my anemometer counts to calculate the wind speed.
Actually the clock interrupt subroutine is just "enable interrupt" and read the RTC.
For the LCD display it's getting an interrupt each 2,5 second via the timer and display the wind value.
In case of gust I want to be informed directly , so not possible to put in main loop.
Here the timer is set to 1 sec and the display to some text. ( need more then one lcd.print to get the hang)
When I check the I2C bus on a logic analyzer, I can see the packet from the RTC and to the display, and also decode the values. (addresses , data)
Due to the fact the two interrupt are not synchronized, the RTC packet can cross sometimes the LCD packet, and it works.
I put timer1 a little bit less then 1 sec to try get this shifting of packets, and also to reproduce the hang. (if timer1 more than one second the hang seems not there)
When the hang occurs, the CPU freeze and also the I2C bus. The clock interrupt stops also, but NOT timer1. It continues to execute the isr_timer subroutine, but hang at the first instruction which access the I2C bus. Timer1 continue his job each second , but the CPU is down so the stack is not pop down, the freeRam decrease at each pass to finally reach zero.
Viewing several capture on the logic analyzer, it seems that the hang occurs when the clock packet is going out of the LCD packet (but the hang is not always there)
Readings different topics I start to understand the heart of the arduino but couldn't find an explanation to my problem.
That's very similar with the old CPU I used to work before to be retired.
(Sorry but english is not my mother language)
Thanks for your help.
Pierre
Troubleshoot_hang_intr_01.ino (1.55 KB)