0
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ How are you resetting the watchdog timer? Is it still getting reset while the ISR is running waiting for the I2C? \$\endgroup\$ – Phil G Jul 18 at 13:27
  • 3
    \$\begingroup\$ An ISR should not be waiting for a message. The ISR should toggle a flag, and your main should wait for the message. \$\endgroup\$ – Scott Seidman Jul 18 at 13:55
  • \$\begingroup\$ 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. \$\endgroup\$ – Spehro Pefhany Jul 18 at 14:18
0
\$\begingroup\$

Assuming you are using MPLABX, go to Window->PIC Memory Views->Config bits.

Select the desired WDT option (one of four) and click on "Generate Source Code to Output"

enter image description here

You will see the required #pragma

#pragma config WDTE = SWDTEN    // Watchdog Timer Enable (WDT controlled by the SWDTEN bit in the WDTCON register)
\$\endgroup\$
  • \$\begingroup\$ Thanks! That's rather nefarious to make the optionals so undiscoverable. I've only been using the IDE to flash the microcontroller and I couldn't find where the options were actually defined in the headers. \$\endgroup\$ – Shane Snover Jul 18 at 15:08
  • \$\begingroup\$ You can also find the info in: /docs/chips/16f1829.html \$\endgroup\$ – Spehro Pefhany Jul 18 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.