Electronic – Microcontroller reset

eepromembedded

I am facing a problem of micro controller reset, I am thinking of implementing the following to find the function in which it happens, then the root cause. As soon as I enter a function I will increment a global variable and store in eeprom. Once a reset happens I can identify the event, as I will start from main, and I will read the last eeprom value. From this I can know at which function reset happened. Now my main concern is whether I will finish the write cycle of that eeprom memory location. The reset happens approximately after every 2 hours. Any better ideas or it is OK to write in eeprom.

Best Answer

Your approach is unlikely to help. First, the reset may be totally unrelated to the current function: a watchdog timeout or a misconfigured ISR are common causes. Second, even if you discover the function which triggers the reset, there's no indication that this function is buggy. Perhaps a variable used by this function was trashed by a stack overflow which occurred somewhere else.

My advice is to strip down your firmware to the most basic core functionality and check if that part can run cleanly. Then you will include additional functions until the reset reappears, and search for errors in the function which was included last.

Also make sure you have plenty of stack space. If you have recursive functions, start by eliminating them or at least checking them scrupulously.

Since you mention you're using CAN, I suggest you check out XCP which can be used for error logging.