cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to change the IWDG timeout in STM8S003

Dileep P D
Associate II
Posted on June 28, 2018 at 10:44

Hi everyone, I am trying to enable IWDG timer and working for me. but i am not able to change the iwdg timeout, it always ~8ms. I am using HSI CLOCK(16MHz) and referring the Example code provided by ST .

I think the maximum iwdg timeout is 1 sec for STM8S003. Am I right??

here is my source code. I am configuring 250ms IWDG timeout. but getting IWDG timeout is < 8ms. please help me to figure out the issue.

LsiFreq=128000; //128khz

void main(void)

{

   /* Configures clocks */

   clock_configuration();

   IWDG_Config();

   while(1)

   {

      /* Reload IWDG counter */

      IWDG_ReloadCounter(); 

   }

}

void IWDG_Config(void)

{

/* IWDG timeout equal to 250 ms (the timeout may varies due to LSI frequency

dispersion) */

/* Enable write access to IWDG_PR and IWDG_RLR registers */

IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

/* IWDG counter clock: LSI/128 */

IWDG_SetPrescaler(IWDG_Prescaler_128;

/* Set counter reload value to obtain 250ms IWDG TimeOut.

Counter Reload Value = 250ms/IWDG counter clock period

= 250ms / (LSI/128)

= 0.25s / (LsiFreq/128)

= LsiFreq/(128 * 4)

= LsiFreq/512

*/

IWDG_SetReload((uint8_t)(LsiFreq/512));

/* Reload IWDG counter */

IWDG_ReloadCounter();

/* Enable IWDG (the LSI oscillator will be enabled by hardware) */

IWDG_Enable();

}
0 REPLIES 0