Preface: This is my first blog, and I am going crazy. I used STM8S003F3, and it took 5 days to solve the problem, but the ending is terrible!
But because of this problem, I seem to have almost fully understood the use of stm8's clock, reset, watchdog, and iar.
Advice: Don’t just believe the information you find on Baidu!
Phenomenon: When the main frequency is only 16MHz, the program resets frequently and is uncontrollable. Other phenomena are abnormal and bizarre and are not explained here to avoid brain damage.
Text: The cause and effect is as follows:
1. I configured a 16M main frequency
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //Internal high-speed clock, no frequency division
Or: CLK->CKDIVR = 0x00; //HSIDIV = 0 CPUDIV = 0 cpu clock = 16Mhz
I found that it frequently reset automatically and the reset speed was extremely fast. I couldn't find the reason, so I asked the boss, and he said the reset was related to IWDG.
2. If you have never learned or set up a watchdog, then configure it.
Basically, it just asked me to configure it. After streamlining various configuration methods on the Internet, all online content is unified as follows:
void IWDG_Init(void) //Configure and start the watchdog
{
IWDG->KR = 0xCC; //Start independent watchdog
IWDG->KR = 0x55; //Write unlock
IWDG->PR = 0x06; //256 division
IWDG->RLR = 0xFF; //Set the reload register
IWDG->KR = 0xAA; //Lock and refresh
// IWDG_Enable(); // Enable watchdog
// IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Write enable
// IWDG_SetPrescaler(IWDG_Prescaler_256); //Prescaler 256,128KHZ/256
// IWDG_SetReload(0XFF); //Set the count value for each dog feeding.
// IWDG_ReloadCounter(); //Feed the dog
}
The operation registers and library functions are available, and there are no errors.
void WDT(void) // Feed the dog
{
IWDG->KR = 0xaa;
}
Just feed the dog regularly. LSI's 256-division frequency feeds the dog about once a second. If it is not fed, it will reset. It looks very simple.
3. In order to solve the problem, I almost mastered the independent watchdog IWDG and ensured that the watchdog configuration was absolutely fine, but the reset problem was still not solved!
Under normal circumstances, the watchdog is optional. It does not mean that it will be automatically initialized when the computer is turned on (the boss's invisible misleading).
If I initialize the watchdog, the watchdog should also be reset once a second, but I reset it n times in a second, which means it has nothing to do with the watchdog.
4. Investigation found that it was related to the clock
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV2); //Internal high speed clock, divided by 2;
The program will not reset when the frequency is divided into 2, 4, and 8. Does it mean that 16M will automatically reset, but below 8M will not reset? But I just want 16M.
The manual says that the watchdog uses LSI, and my main frequency uses HSI, so they won't affect each other, right? (They won't affect each other)
5 I am going crazy. I have to deliver the task, but problems arise along the way.
Delete all the code and leave only a few sentences
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //Internal high-speed clock, no frequency division
GPIO_Init(Laser_V1_Port, (GPIO_Pin_TypeDef)Laser_V1_Pin, GPIO_MODE_OUT_PP_LOW_SLOW); //灯亮
int i=1000;
GPIO_WriteHigh(Laser_V1_Port,Laser_V1_Pin);
while(i--);
GPIO_WriteLow(Laser_V1_Port,Laser_V1_Pin);
while(1) { }
Logically, it should light up once when it's turned on, but now it stays on all the time (because it's reset)
I found someone else's demo to try, but it was still the same. However, when I tried it with another STM8 development board, it worked!
6 Finally, I found that if while(1){} is removed, it will no longer reset. If while(1){} is not removed, the light will still flash continuously.
Damn, this is not a reset at all, but the operation of the light flashing is inexplicably looped, not caused by the reset! ! ! ! Damn, this is a movie, so convoluted!
7The problem was not found, but it was solved, that is:
In the main() function, if while(1) is empty, will unexpected code in while(1) be executed? Just don't leave while(1) empty.
What the hell is this? It's clearly a technical post, but it's like approaching science (ignoring the process in between)
8On the last day, I almost gave up and finally wondered if it was a hardware problem?! My inner thoughts: It has nothing to do with hardware!
Finally: Vcap changed its capacitance from 103 to 105 and the reset problem miraculously did not occur anymore (1uF).
Why did I choose 103? !Ah? Because I just copied it from Baidu Library! What a pitfall! (NRST didn’t add capacitors!)
Previous article:【stm32f407】Window watchdog wwdog
Next article:STM8S——watchdog (IWDG)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Make announces its return
- The mysterious EMC, how did it come about?
- EEWORLD University - Zero-based circuit learning
- Appointment viewing double gift: How to ensure edge computing security? Learn about an important tool
- [Sipeed LicheeRV 86 Panel Review] 6-socket to achieve communication between different processes
- Usage diagram of various Arduino basic components
- [Transfer] C compiler version and predefined macros for system judgment
- AD21 interactive fast manual layout skills PCB reposition selected components in sequence reposition selected c...
- Diode frequency multiplier circuit, transistor frequency multiplier circuit
- [Silicon Labs BG22-EK4108A Bluetooth Development Evaluation] + Environment Construction SimplicityStudio-5