2021-03-07 10:40 AM
Here is my source code:
void CLOCK(void){
RCC_DeInit();
RCC_LSICmd(ENABLE);
RCC_HSEConfig(RCC_HSE_ON);
while(RCC_WaitForHSEStartUp()==ERROR);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_PLL2Cmd(DISABLE);
RCC_PLLCmd(DISABLE);
RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE,RCC_PREDIV1_Div1);
RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_8);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)!=SET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
while (RCC_GetSYSCLKSource() != 0x08){}
}
int main(){
unsigned long int counter;
CLOCK();
GPIOS();
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(IWDG_Prescaler_32);
IWDG_SetReload(500);
IWDG_Enable();
while(1)
{
counter=counter+1;
Print(counter);
if(counter>6553500){counter=0;}
IWDG_ReloadCounter();
}
}
I have set my watchdog counter to 500( .
second)(Stm32f107, LSI=40Khz,Prescale=32 ). By ignoring the "IWDG_ReloadCounter(); " (I commented //IWDG_ReloadCounter();) , this watchdog resets my MCU after about 3 seconds instead of .4 seconds. I need what my problem is.
Solved! Go to Solution.
2021-03-07 12:19 PM
Is this SPL? What do those function do? Do they wait until the status register indicates the writes are finished?
Try one call of IWDG_ReloadCounter() just after IWDG_Enable(), before while(1). Does it make any difference?
JW
2021-03-07 11:13 AM
Look in the datasheet for the tolerance of LSI. For F072 it is 30 min, 40 typ, 50 max kHz. But your error 0.4 vs 3 points to errors in your code. For me it does not make sense...
2021-03-07 12:19 PM
Is this SPL? What do those function do? Do they wait until the status register indicates the writes are finished?
Try one call of IWDG_ReloadCounter() just after IWDG_Enable(), before while(1). Does it make any difference?
JW
2021-03-07 06:55 PM
Thank you very much, it works fine. I really appreciate your help.
2021-03-07 06:55 PM
Thank you very much for your comment.