Bizarre Memory Corruption

Hey, I'm using a Duemilanove to communicate with a raspberry pi via XBees. I'm using arduino-xbee to use the XBee api to communicate with them.

I'm having some bizarre issues though. I have a fairly large sketch (20k compiled) and it frequently sends different messages back to the raspberry pi. Most of the time it works but sometimes the raspberry pi never receives the message. However, the LED on its explorer board flashes to indicate that it received it making me think that the message got corrupted. It only happens when I try to send certain messages of a certain length at certain times, however. In one case, the raspberry pi will receive the message if it is 11 or 13 characters but not 12. I've also noticed that around the same time, one of my other variables has an unexpected value and its value changes from run to run.

freeMemory reports ~600 bytes of free memory but this definitely appears to be a memory related issue. I pretty much don't use malloc after initialization so I'm pretty much at a loss as to what this could be. This is for a very important project so any help is much appreciated!

All hands to the Ouija board, crystal balls on standby.

Any time you transmit data wirelessly or over long distances there is potential for errors. Computer networks or the Internet wouldn't work without error detetection/correction...

If it's corruption caused by a bug and not data transmission error, look for a case where you write-past the end of an array. (i.e. You write to element '10' in a 10 element array that goes from 0-9.) This can sometimes happen in a loop, when you don't stop the loop in time.

Also make sure that you are writing a value that's too large for the variable type. And, made sure you are not using signed variable types when the value is unsigned.

Otherwise, use the serial monitor to check variable values and simplify the code to narrow-down where the problem is occuring. Sometimes I'll send/display little messages like "Starting Transmit()" to tell me what the program is doing.

DVDdoug: Any time you transmit data wirelessly or over long distances there is potential for errors. Computer networks or the Internet wouldn't work without error detetection/correction...

If it's corruption caused by a bug and not data transmission error, look for a case where you write-past the end of an array. (i.e. You write to element '10' in a 10 element array that goes from 0-9.) This can sometimes happen in a loop, when you don't stop the loop in time.

Also make sure that you are writing a value that's too large for the variable type. And, made sure you are not using signed variable types when the value is unsigned.

Otherwise, use the serial monitor to check variable values and simplify the code to narrow-down where the problem is occuring. Sometimes I'll send/display little messages like "Starting Transmit()" to tell me what the program is doing.

I don't think it's a size issue. The xbee api takes a uint8_t * and the size of the array. I debug both the uint8_t * and the size over serial and they are always what I expect. The code also works most of the time. It only breaks with certain length strings at certain points during execution. In other words, if I send string X at the beginning it works but not in the middle of the routine. Plus, if I add or remove a character from X it will also work. Plus, when I say it doesn't work, the receiving xbee board receives the message but the hardware throws the message out (presumably because it doesn't match the checksum or something similar)

prototype1010: I don't think it's a size issue.

No, most likely it's a problem with your hardware or software.

PeterH:

prototype1010: I don't think it's a size issue.

No, most likely it's a problem with your hardware or software.

You are correct. After about 12 hours of debugging, I discovered that the python xbee api defaults to unescaped characters while the arduino one defaults to escaped. The crazy part is that it only mattered in very specific circumstances...