Friends who often contact MCUs must have encountered the problem of running the MCU program. Because the program is more complicated, it is more difficult to find the place where the error occurs once the phenomenon of running out. The explanation and solution for the error on the network are also quite varied and not easy to find. Xiao Bian specially helped everyone to sort out the reasons for the MCU program running dead, let's take a look at whether you can find the answer you want in it.
The single-chip computer crashes and can fly to find the reasons from the following aspects:
1. Unexpected interruption.
Whether an interrupt is turned on, but the middle flag is not responded and cleared, causing the program to enter the interrupt all the time, causing the illusion of crash.
2. The interrupt variable is not handled properly.
If you define some global variables that will be modified in the interrupt, you should pay attention to two problems: first, in order to prevent the compiler from optimizing the interrupt variables, add volaTIle before the variable definition, and then read the interrupt variable before the main loop. The global interrupt should be closed first, to prevent half of the read from being interrupted and modified, and then open the global interrupt after reading; otherwise, the data will be messed up.
3. Address overflow, a common error is a pointer operation error.
I want to emphasize that the array subscript uses the loop function in the loop function. If the loop variable is not controlled, the array subscript will be out of bounds, and the register of the system will be accidentally modified to cause a crash. In this case, if the crash indicates good luck, otherwise it will be followed. I don't know what a headache is happening.
4. Unconditional infinite loop.
For example, use while(x); wait for the level change, under normal circumstances x will become 0, just in case, so it is best to add a time limit.
5. The watchdog is not closed.
Some single-chip microcomputers may accidentally automatically turn on the minimum cycle watchdog even if the watchdog is not turned on, causing the software to reset continuously, causing a crash. This depends on the chip manual. It is best to explicitly clear the program after resetting. The dog then closes the watchdog.
6. Stack overflow.
The most difficult problem to find, for small-capacity microcontrollers, try to reduce the level of function calls, reduce local variables, and thus reduce the space required for stacking. When you have tried all the above, you can't solve the problem. Try to put your called less function directly into the calling place and change the local variable that takes up RAM to a global variable. Try it maybe you can. .
Through this article, have you found the solution to the problem you want? Even if it is not found, this article can help you prevent the occurrence of running away to some extent.
Mc4 Fuse Connector,Slocable Solar Pv Fuse,Mc4 Connector With Fuse,Mc4 Inline Fuse Connector
Sowell Electric CO., LTD. , https://www.sowellsolar.com