Very odd error

I have a program... I can't post the whole thing but it's pretty big (compiles to around 8300 bytes). It interfaces with a biometric module, a 20x4 LCD, and a 5 key pad. It interfaces with the biometric module through a MAX232 chip. I'm using a boarduino. I've successfully compiled and run the program so far (running over a hundred different versions.) It uses Lady Ada's software serial (the version that comes with the latest SVN arduino development program which I am also using) to access the LCD. Hopefully that gives a decent background as to what I'm trying to do.

Now, the error. If I include a certain function (which, in this case, is a function to enter administrator mode on the biometric module) then basically the whole rest of the program will go haywire, trash will be displayed instead of the proper data on the LCD. The program resets at a certain spot if I leave the program as is. If I comment out a few initialization functions it will get to a main menu but the text will be mostly trash. I do not have to even call this function. It just has to be compiled into the program. The function is fairly large but the 8300 bytes is including that function. It's less without the function (seems to compile to 7082 bytes.)

My only guess is that I've somehow run out of my 1K of RAM and it is thus wrapping around. But the program doesn't ever get to the point at which it would call the function and it's already messing up. So I don't think it should be allocating any RAM space to a function which never runs... It appears as if the function compiles to more than 1K. Is that a problem? I'm really completely stabbing in the dark. I have no idea how a never called function can mess up the rest of the program so badly...

My only guess is that I've somehow run out of my 1K of RAM

From your description it certainly sounds likely that could be the case.

--Phil.

Even though I never actually call the function in question? Can it somehow take up RAM even before it runs? Given the size of the program I would not be surprised if I'm running really close to the limit but why would an as of yet unused function throw me over the limit? Is there a good way, other than seeing the program die, to figure out when a memory address wrap has occurred?

I just thought of it... The function in question has a lot of string literals in it. I seem to remember something about avrlib functions to deal with program memory strings.... which means that normal strings are stored in RAM instead of flash aren't they? If that's true then I am almost certainly running out of RAM because of the function and my only solution would be to use PGMMEM strings and maybe swap the strings into RAM as needed.

Sounds like you have found the problem and its solution. You can verify that is the cause by commenting out or deleting the body of the function in question and if that allows the sketch to work then you will need to move the string constants into program memory.

I agree with mem, sounds like you've hit the ram wall as it were. Move any constants you have into flash and hopefully that should fix your problem. From what I've seen the "trash" text you're describing sounds like filling up the ram and then having the data get corrupted by writing over itself.

The playground has information on how to use EEPROM and the Flash ram aswell as how to tell how much RAM you have left to use: http://www.arduino.cc/playground/Main/GeneralCodeLibrary