Passing Parameters and assigning an array of chars - Part 1

I have the UNO v3 (playing around with it, new to microcontrollers).
I’m working with the SEEED SD shield (V3).
Writing to it is not a problem…Working on reading the file. In the process I have uncovered some issues:
1- it appears, passing parameters in functions causes garbage to be pumped out to the USB port (thus the Serial window).
2- trying to assign a global array by indexing it also causes garbage to be pumped out to the USB port.
The code:

const int CS_PIN = 10;
// We set this high to provide power
const int POW_PIN = 8;

const int SwitchPin = 2;

char pFileName = “Arduino1.txt”;

char GlobalBuffer[1000];

char *str = "John ";
File InDataFile;

void setup()
Serial.begin( 9600);
Serial.println(" Initializing Card");

pinMode( SwitchPin, INPUT);
Serial.println(" SwitchPin");

// CS pin is an output
pinMode( CS_PIN, OUTPUT);
Serial.println(" CS_PIN");

// Card will draw power from pin 8, so set it high
pinMode( POW_PIN, OUTPUT);
Serial.println(" POW_PIN");

digitalWrite( POW_PIN, HIGH);
Serial.println(“digitalWrite POW_PIN”);

if (! SD.begin( CS_PIN))
Serial.println(" Card Failure");
Serial.println(" Card Ready");

//Serial.println(“About to GlobalBuffer[0] = ‘J’”);
//GlobalBuffer[0] = ‘J’;
Serial.println(“About to ReadData()”);

now the first image is with the Serail.println & GlobalBuffer lines commented out. The 2nd image is with those two uncommented. Have to scroll to the right on the Serial window a bit just to see the garbage as the first part is all blanks (or nulls chars?)

I’ll address the passing of parms in functions in a different post… unless someone knows I can’t do that? I was passing the handle to the File and reference to a buffer… once I took those parms out, at least I wasn’t running into issues.



char GlobalBuffer[1000];

this buffer already takes half of the memory, are you sure you need it? It sounds like an OUT OF RAM problem.

  1. I always advice to use high baudrates e.g. 115200 send data 12x as fast to the PC.

WOW, I reduced the array down to 80 bytes... that least the assigning index 0 of the array. 1000 bytes is too much memory? This will take some planning...hmmmm

So how well does arduino handle pushing parms on the stack when being passed in functions?

An UNO only has 2000 bytes RAM for variables..
You can use the F() macro to store the const strings in flash... saves a few dozen bytes?

thanks, reducing the memory footprint took care my issues, including passing parms.

I'll keep in mind F() ... that ought to be interesting to play with....