Question
Stop iwdg in halt mode on STM8L051F3
Hey
I have tried to use the option byte to stop the iwdg when i enter halt.
I can see that i manage to set the WDG_HALTin option byte 3.
But the watchdog still resets the MCU after i enter halt.
Please help me, cant i do it? If so then how do i read that from the documentation.
If i can what am i doing wrong?
I can reproduce the problem with this code:
void halt_test(void) {
// switch to 16MHz (default is 2MHz)
sfr_CLK.CKDIVR.byte = 0x00;
// Setup LED
sfr_PORTB.DDR.DDR2 = 1; // input(=0) or output(=1)
sfr_PORTB.CR1.C12 = 1; // input: 0=float, 1=pull-up; output: 0=open-drain, 1=push-pull
// Disable LED
sfr_PORTB.ODR.ODR2 = 1;
for (uint32_t i = 0; i < 600000; i++) {
NOP();
}
// unlock w/e access to EEPROM & option bytes
sfr_FLASH.DUKR.byte = 0xAE;
sfr_FLASH.DUKR.byte = 0x56;
// wait until access granted
while (!(sfr_FLASH.IAPSR.DUL))
;
// Enable write to option bytes
sfr_FLASH.CR2.OPT = 1;
// Set IWDG_HALT bit
sfr_OPT.OPT3.byte = 0b10;
// wait until end of programming
while (!(sfr_FLASH.IAPSR.EOP))
;
// Disable write to option bytes
sfr_FLASH.CR2.OPT = 0;
// lock EEPROM again against accidental erase/write
sfr_FLASH.IAPSR.DUL = 0;
// start IDWG (must be the first value written to this register, see UM)
sfr_IWDG.KR.byte = (uint8_t)0xCC;
// unlock write access to prescaler and reload registers
sfr_IWDG.KR.byte = (uint8_t)0x55;
sfr_IWDG.PR.PR = 6;
// set timeout period 0xff = 1724.63ms according to RM0031
sfr_IWDG.RLR.byte = 0xff;
// start IDWG
sfr_IWDG.KR.byte = (uint8_t)0xCC;
// Enable LED
sfr_PORTB.ODR.ODR2 = 0;
ENTER_HALT();
}