The single-chip program always runs? Tips to help you

    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.

    PV Fuse Connector

    Mc4 Fuse Connector,Slocable Solar Pv Fuse,Mc4 Connector With Fuse,Mc4 Inline Fuse Connector

    Sowell Electric CO., LTD. , https://www.sowellsolar.com

    Previous Post: 10 steps to select the microcontroller
    Next Post: [LED Chinese knot details] teach you how to buy LED Chinese knot
    Home
    Recent Posts
    • Feile Audio (Shanghai Yaming) plans to increase …
    • What are the big brothers in the top festival ta…
    • How to reduce the power consumption of handheld …
    • The 13th Summit Forum Lumileds: Zhou Xuejun talk…
    • The first ride YunOS2.1 system open Bor M6 enhan…
    • Interpretation of Internet TV Radio and TV Polic…
    • Modified LED low beam heat dissipation performan…
    • Philips scientists develop new warm white LED li…
    • Japan develops a new revolution in the history o…
    • Huada DV7810-T2 installs third-party application…
    • Millet mini TV box to install third party softwa…
    • Cool open A43 future version of the quick out of…
    • Grand switch breaks through bottleneck in indust…
    • Xinyichang: the leader of domestic solid crystal…
    • The thirteenth summit forum sunshine lighting: h…
    • MulticoreWare Introduces Advanced VP9 Decoder fo…
    • Nokia China Criticizes More Than 170 People for …
    • Smart TV platform worth trillions
    • Kai Bor M9 evaluation home monitoring + parental…
    • Xiaomi pushes smart home products