-
Notifications
You must be signed in to change notification settings - Fork 1
Application hangs and is not responsive to user's actions #3
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
I have found Megunolink/ArduinoCrashMonitor which uses watchdog feature to:
After some tries I have found two different places, where it freezes:
Interesting. |
…duinoCrashMonitor to find where the code freezes.
I'm using arduino hardware in version 1.6.17. |
I just want to summarize some things, before I proceed with investigations:
It could be that all of the facts above make, that it is easy for me to reproduce the issue when the program freezes in Wire library. It may be a good entry point to investigate the Wire library and try to improve something. |
As I have written before, I started to use ArduinoCrashMonitor. I'm using this library to:
Additionally I added a piece of code in the Arduino's loop, that will blink the internal diode. If the diode is blinking then it means that loop is being constantly executed and the program doesn't freeze. The plan is: download Adruino sources and try to modify internal Wire library. Some hints can be found: |
With 703496c commit (and a commit before) and standard Wire library and ArduinoCrashMonitor, I have noticed the following behavior:
|
With wmarkow/Arduino@4028bdc commit of my Arduino's fork I have modified the Wire library so it have a timeouts in twi_readFrom or twi_writeTo methods where it checks the twi_state variable. With my modified Wire library and ArduinoCrashMonitor, I have noticed be following behavior:
Sometimes the the code freezes, the internal diode stops blinking and program doesn't respond to user actions (like changing volume, LCD is not updated). Probably this is a result of not all Next part of my investigation is a loop in void twi_stop(void) method. |
With wmarkow/Arduino@afc25a6 commit of my Arduino's fork I have modified the Wire library so it now has a timeout in void twi_stop(void). Since this method is executed from interrupt With this solution I have never observed a freeze (however I didn't modified all while loops yet). The LED still blinks (but blinks slower, so the timouts are working), so the Arduino's loop Good thing that Arduino not freezes but my program is still not responsive to user: probably because there is something wrong with I2C and I can not communicate with my devices by I2C: LCD is not Maybe I'm missing something and to recover from that state I need to do something else (like setting some specific TWI register)? |
With arduino/Arduino@b325055 commit I have managed to recover TWI interface (at least it works in my project). |
hello, i just notice your work. Instead of millis() you can use micros(), that will be updated even in a ISR state, as is done by HW. Rember that when the system freeze, the best solution in reset the HW i2c and restart teh operation. I suggest using the TWI library directly (is what wire uses under the hood) has it will give you control over what you need |
@MauroMombelli, thank your your comment. Actually in my work I have used your pull request mixed with DanNixon's pull request. Maybe I have reinvented the wheel again a bit, but by the way I learned new things. By using TWI library directly you mean to use what is in *Wire\src\utility* directory (twi.c and twi.h)? |
the way DanNixon uses the twi_guard() function is really elegant. The advantages of micros() would be to make the timeout idipendenet from the clock source; it may avoid future issues and yes, that is the twi library, there you see how I2C work at register level, and is quite easy. |
I agree that using Calling What will happen if we use
We can even calculate that tiem by putting the values into the equation above:
which becomes
which is 2044 us (2ms). I have the feeling that using |
After two years I come back to the issue. In the meantime I have installed a new RF antenna so my RDA5870 chip gets a better reception and the issue is now harder to reproduce (I have tried to reproduce it with the same USB wall charger). But I have found a very easy way to reproduce it:
|
I did further tests with the latest fix from arduino/ArduinoCore-avr#107 In my coe I'm checking for the TWI timeout flag by calling When I:
In my solution I put a 10000us as a timeout value. The fix helps me to recover from the endless loop. |
I have noticed that since some time (when I started to use RDS) application hangs. It is not responsive: the LCD screen freezes and do not displays new RDS messages or do not displays current volume. Moreover, it is not possible to change volume; nothing works. After power reset it works fine, until it hangs again.
This issue is highly reproducible when I power up the system from USB wall charger by Chicony Power Technology, AC Adapter, Model W12-010N3B. When I power up the system from my laptop's USB it hangs very rare. So it has something to do with the power supply.
However it would be good to know at what line of the source code it hangs. It would be a good idea to use watchdog to reset the board.
The text was updated successfully, but these errors were encountered: