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!