tags:

views:

65

answers:

2

I have a situation where I am writing commands to a command buffer. When it is time for a command in the command buffer to be executed, the command is processed and sent out the UART to another subsystem. When the command is processed, the data that needs to be sent out the UART is stored in a queue and a flag is raised. Then shortly after my main while loop checks to see if the flag has been raised, and if so, sends the data out the UART. However, between the time the command is processed, and the time it is ready to send out the UART, the array gets corrupted. I know this because I am using an in-circuit debugger and setting breakpoints. What in the world is going on, and how do I fix this?

This is an example of what happens:

Right after processing and storing in queue (a[] is the queue):

a[0] = 0x3;
a[1] = 0x6;
a[2] = 0x9;

Right before it is ready to be sent out UART:

a[0] = 0x3;
a[1] = 0x6;
a[2] = 0x0;

or sometimes even,

a[0] = 0x3;
a[1] = 0x0;
a[2] = 0x0;

Behavior is random. Sometimes only one byte gets corrupted, and other times, two bytes.

A: 

Set a watch on the bytes. That way, the debugger will stop when anyone writes to them.

Aaron Digulla
Programming language is C, using MPLAB IDE, with an ICD2, and Microchip PIC24FJGA110
A: 

Sounds like a memory scribble. Something else out there is unexpectedly accessing your array's memory. This could be due to pointers to freed memory not being set to NULL or possibly some hardware writing to the same memory. Impossible to say without more info.

doron