0
\$\begingroup\$

I am working with the PIC24FV16KM202.

I am encountering resets while implementing Dispatch, which is a serial protocol that I'm working on that grew out of a project.

The example that I'm working on is a function that executes when an endpoint has been sent data. I'm using a Python script to send that piece of data through the UART to the uC. When that data is received, mySubscriberFunction is executed.

void mySubscriberFunction(void){
    static uint16_t i = 0;

    i++;

    /* publish i back to the sender to 'close the loop' */
    DIS_publish("i,u16", &i);
}

As you can see, mySubscriberFunction is pretty simple. It increments a counter and publishes the data back to any other subscribers. My Python script is receiving this data and displaying it in the console.

My problem is that after i is ~998 (it has happened somewhat higher and lower, but usually 998), it simply resets. When I'm running in debug mode, the debugger stops executing. When I'm running in production mode, i simply resets to 1 and continues counting.

Another thing that is odd is that, during debugging, I have paused the debugger. If I pause the debugger at i=100, then the reset occurs at ~1098 instead of ~998. If I pause at i=200, then the reset occurs at ~1198 instead of ~998, and so on.

The usual suspects for this sort of reset are attempting to execute an interrupt that doesn't have an interrupt vector, overwriting the PC and/or stack with garbage, or other fun and difficult-to-debug problems like that. I was just hoping that someone out there might have experienced a similar problem and could point me in the correct direction.

Dispatch isn't a large project, so it is plausible to look through the code to spot the problem, but I suspect that the debugger symptom will point someone in the correct direction. Thanks!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Rookie mistake. I found another facet of the symptom, that it was time related and not i related. This is usually a dead giveway that the Watchdog Timer is resetting the device.

I had copied the 'config.h' file from another project in which I was using the WDT; however, I didn't clear the WDT in this project.

The solution: Turn off the watchdog timer or clear the watchdog timer.

Thank you for your patience,

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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