uploading takes forever

If I use the function below the uploading of the pde takes a few seconds:

void WriteFile(char Filename[ ])
{
  myFile = SD.open(Filename, FILE_WRITE);
  if (myFile) {
    Serial.print("Writing to ");Serial.print(Filename);Serial.println("...");
    myFile.println("some line of text");
    myFile.close();
    Serial.println("done.");
  }
 else {
Serial.print("error opening ");Serial.println(Filename);
  }
}

But if I change the function as shown below the compiling is done in seconds but the uploading takes forever:

void WriteFile(char Filename[ ], char myTextLine[ ])
{
  myFile = SD.open(Filename, FILE_WRITE);

  if (myFile) {
    Serial.print("Writing to ");Serial.print(Filename);Serial.println("...");
    myFile.println(myTextLine);
    myFile.close();
    Serial.println("done.");
  } 
 else {
Serial.print("error opening ");Serial.println(Filename);
  }
}

Can anyone tell me what I'm doing wrong!?

Best regards,

Alban

after "forever" I get:

Binary sketch size: 13562 bytes (of a 258048 byte maximum)
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500_2_ReceiveMessage(): timeout

How is your function supposed to determine how large the arrays are? You should either explicitly define the sizes, or change to pointers.

void WriteFile(char Filename[16], char myTextLine[24])

or

void WriteFile(char *Filename, char *myTextLine)

The problem may not be with that snippet of code, but with how you call that snippet.

Post all of your code.

What are you uploading to? Using what OS?

First off all, thanks for the reply!!!

I’m uploading to an Arduino Mega 2560 using v0022 on windows 7 x64

This is my test code:

/* SD card read/write
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - DI
 ** MISO - DO
 ** SCK - CLK
 ** SS - should always be OUTPUT
*/
 
#include <SD.h>

File myFile;

int CS = 30;
int SS = 53; 

#include <MomentaryButton.h>

#define PIN_BUTTON1 2
MomentaryButton button1(PIN_BUTTON1);

#define PIN_BUTTON2 3
MomentaryButton button2(PIN_BUTTON2);

void setup()
{
	SetupSDcard();
  
	button1.setup(); // set as INPUT, set HIGH
	button2.setup(); // set as INPUT, set HIGH
}

void loop()
{
	CheckButtonClicks();
}


void SetupSDcard() {
	pinMode(SS, OUTPUT);
	Serial.begin(9600);
	Serial.print("Initializing SD card...");
	// Note that even if it's not used as the CS pin, the hardware SS pin should be set to OUTPUT
	pinMode(CS, OUTPUT);
   
	if (!SD.begin(CS)) {
		Serial.println("initialization failed!");
		return;
	}
	Serial.println("initialization done.");
}

void CheckButtonClicks() {
	button1.check();
	if (button1.wasClicked()) {
		// Respond to the button being briefly closed, then released.
		Serial.println("Button1 was clicked");
		WriteFile("piet.txt","my line of text");
	}
  
    button2.check();
	if (button2.wasClicked()) {
		// Respond to the button being briefly closed, then released.
		Serial.println("Button2 was clicked");
		ReadFile("piet.txt");
	}  
}

void WriteFile(char Filename[ ], char TextLine[ ])
{
	// open the file. note that only one file can be open at a time,
	//so you have to close this one before opening another.
	myFile = SD.open(Filename, FILE_WRITE);
  
	// if the file opened okay, write to it:
	if (myFile) {
		Serial.print("Writing to ");Serial.print(Filename);Serial.println("...");
		myFile.println(TextLine);
		
		// close the file:
		myFile.close();
		Serial.println("done.");
	}
	else {
		// if the file didn't open, print an error:
		Serial.print("error opening ");Serial.println(Filename);
	}
}

void ReadFile(char Filename[ ])
{
	// re-open the file for reading:
	myFile = SD.open(Filename);
	if (myFile) {
		Serial.print(Filename);Serial.println(":");
		
		// read from the file until there's nothing else in it:
		while (myFile.available()) {
		Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
	} 
	else {
		// if the file didn't open, print an error:
	Serial.print("error opening ");Serial.println(Filename);
	}
}