STM8 about IWDG watchdog and HSI high-speed clock and reset pit

Publisher:清新时光Latest update time:2019-11-07 Source: eefocusKeywords:STM8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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!)

Keywords:STM8 Reference address:STM8 about IWDG watchdog and HSI high-speed clock and reset pit

Previous article:【stm32f407】Window watchdog wwdog
Next article:STM8S——watchdog (IWDG)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号