Object Method call causing variable reset

I am baffled by the behavior of my sketch. It's relatively large, so I'll only post the relavant lines here:

uint32_t lateCounter = 0;
.
.
.

if ( (!timer_SampleRate.delayTillExpired()) )
{
printf("LateCount updating...\r\n");
lateCounter++;
printf("Late Counter updated to %d on sample %d\r\n", lateCounter, i);
}
.
.
.

printf("lateCount pre = %d\r\n", lateCounter);
samples = pMAX11206->maxGetADC();

  • printf("lateCount post = %d\r\n", lateCounter);*
    This is generating the following output:...
    LateCount updating...
    Late Counter updated to 1 on sample 5
    lateCount pre = 1
    lateCount post = 0
    It's clear that the member function maxGetADC() is causing lateCount to be reset back to zero (I've tried just calling that method and it not doing anything). But from the code alone, that shouldn't be happening. >:( Does anyone have any clues as to how this could happen? If it's relavent, I'm using the visual micro plugin in visual studio 2013 to build a sketch for the Arduino Due.

Only if you already know what's causing the problem can you know what lines of code are relevant. If the problem was in those few lines then I'm sure you would see it. It is impossible to diagnose what happens in that method call without seeing it. Post all the code if you need help. Or at least write a minimal sketch that will compile and run and demonstrate the problem.

Maybe the thing that's causing your outbreak of italics is your problem.

If you posted your code, in code tags, we might know.

All right. The project is attached. Like I said, its a bit large.

The problem I’m having I can trace back to the “Commands.cpp” file Ln 445. The local variable in that function ‘lateCounter’ is somehow being reset by the ‘maxGetADC’ function call, but it shouldn’t. I don’t know how I can further troubleshoot this, as lateCounter is not in the scope of ‘maxGetADC’. So I can’t put any debug lines in side of ‘maxGetADC’.

Other function calls to similar objects don’t do this ‘pMCP3553->getADC()’ does just fine. As does pAD7171->getADC().

Front_End_Eval_Control.zip (65.7 KB)

You forgot to include the dot-ino file; the actual sketch.

I'm afraid I don't understand. I have the dot-ino file in there. I'm able to open it with the Arduino IDE, compile and upload from just the contents of that folder. Can you elaborate further?

Huh. There is one in there. Sorry about that.

No worries. We all make mistakes. And I think I found mine.

When I finally got smart enough to turn on compiler warnings, it flagged a large number of things. I was generally using the %d specifier for uint32_t types. I fixed that and started using %ld instead. That, for some reason, seems to have fixed my issues. I think the lesson here, which I’m sure I’ll have to learn again, is to always pay attention to compiler warnings. :-[

		if (ui32_rxBufferPos > MAX_SERIAL_INPUT_BUFFER)
		{

Too late. When ui32_rxBufferPos is greater than MAX_SERIAL_INPUT_BUFFER your program has already written past the end of c_Command_Rx_Buffer.

A buffer overrun would explain the symptom. I suggest checking for any more buffer overruns.

Wasn't actually related to my issue. And my buffer is currently way larger than it needs to be. But you're right. I should have had >= there. Thanks for pointing that out.