# How to enable PIC16 watchdog timer for software control?

I am working on a project where I have an I2C slave application running on a PIC16F1829. I am finding that because the ISR must read the slave address, wait for a new byte, then read that byte, that very occasionally the bus will hang due to the micro being stuck in the ISR.

I've tried to enable the watchdog to counter this behavior, but it doesn't seem to have been done correctly. I've tried #pragma config WDTE = ON to enable the watchdog followed by setting up the period and enabling the SWDTEN bit, but this doesn't seem to do the trick. In the documentation, it's mentioned that the WDT fuses have four possible settings, so the presence of just ON and OFF for the fuse setting is making me suspicious.

Does anyone have any additional insights on what I'm doing incorrectly?

• How are you resetting the watchdog timer? Is it still getting reset while the ISR is running waiting for the I2C? – Phil G Jul 18 '19 at 13:27
• An ISR should not be waiting for a message. The ISR should toggle a flag, and your main should wait for the message. – Scott Seidman Jul 18 '19 at 13:55
• Agree 100% with @Scott's comment. This is the wrong overall approach. Get in and out of ISRs as quickly and as deterministic-ally as possible. – Spehro Pefhany Jul 18 '19 at 14:18

#pragma config WDTE = SWDTEN    // Watchdog Timer Enable (WDT controlled by the SWDTEN bit in the WDTCON register)