I am writing an arduino sketch for a one use only barcode system. currently I have 2 arduinos, one with a USB host shield dealing with the scanner and a second with a keyes data logging shield. The USB shield arduino takes the scanned barcode and sends via serial connection to the data logging arduino.
On the data logging arduino side I seem to be getting a lot of strange issues with the SD operations. Writes tend to be ok but when reading from the SD card i seem to be getting a lot of gibberish.
When using the SdFat object I run out of global variable space (89%) being used up hence why I moved that object to within the functions its called in.
If anyone could give me some pointers on how to sort out these SD issues I would grateful,
how much RAM used when the serial is included?
Perhaps you're running out of free ram for stack/strings/heap usage.
Are your char buffers large enough?
Sketch uses 24,054 bytes (74%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,143 bytes (55%) of dynamic memory, leaving 905 bytes for local variables. Maximum is 2,048 bytes.
You are doing a lot of memory allocations by doing this. Possibly you are getting fragmentation, as Ps991 has hinted at. You are much better off using a static array of characters, and probably not passing that around all over the place like you are doing.
andyowenwest:
When using the SdFat object I run out of global variable space (89%) being used up hence why I moved that object to within the functions its called in.
Moving that object doesn't fix the problem though. The memory usage you see on compile only tells you about the global variables, so you made that number look nicer. BUT, the SdFat object still has to be allocated when that function is called, it just happens on the stack now instead of the heap. You're still using the same amount of memory at that point, you've just hidden that fact from yourself.