STM32 Learning notes the use of independent watchdog (IWDG) __stm32 Learning Notes

Source: Internet
Author: User

To STM32 any module before the use of its initialization, the first is to initialize the peripheral clock, you can simply look at the system clock chapter on peripheral clocks, look at the data manual is as follows: 
The watchdog is driven by an independent internal 40M clock, so it does not require us to configure the registers in the initialization clock. 

Read the data manual can know the watchdog module uses the system LSI clock, before initialization configuration to set up the pre-allocation register IWDG_PR, and set the IWDG_RLR two registers, because the register is write-protected, according to the data manual know: 

        therefore, before the register must be set before the IWDG_KR (key register) to write to 0x5555, modify the register value. next look at the Prescaler frequency register : 

The Prescaler factor mainly relates to the watchdog's time-out period. Read the manual: 

(I don't delve into the maximum value here), then we look at the automatic load register: 

sets the initial value of the IWDG_PR and IWDG_RLR.

We calculate the watchdog's dog-feeding time (watchdog overflow time) formula:

tout= ((4*2^prer) *rlr)/40

where Tout is the watchdog overflow time (unit ms), Prer is the watchdog clock Prescaler frequency value (IWDG_PR value), the range is 0~7,RLR bit watchdog overload value (IWDG_RLR).


For example, we set Prer to 4, RLR value of 625, we can calculate the tout=64*625/40=1000ms, so that the watchdog overflow time is 1S, as long as in this second, once inhaled 0XAAAA to IWDG_KR, will not cause to see Door Dog Reset. 
so the initialization function is as follows: 
void Iwdg_init (4,625) { iwdg->kr=0x5555; Unlock Register Protection iwdg->pr=prer; Write initialization frequency value iwdg->rlr=rlr; Write Auto Load value iwdg->kr=0xaaaa; Turn on Register protection iwdg->kr=0xcccc; Start the watchdog . } 
after initialization, the watchdog begins to gradually decrement the count to 0000 and reset, so keep feeding the dog before resetting , that is, constantly reload data into IWDG_RLR to prevent reset 
The dog feed function is as follows: 
void Iwdg_feed (void) { iwdg->kr=0xaaaa; } 
when the basic independent watchdog configuration completes initialization, the dog feeding program can be invoked in the appropriate place.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.