Go Down

Topic: SD card write problem (Read 1 time) previous topic - next topic

flytroll

Hello,

I'm trying to connect SD card shield to Arduino.
Using this SD module:

http://cgi.ebay.com/Arduino-SD-Card-Module-Make-Read-Write-SD-Card-EASY-/270712482798?pt=LH_DefaultDomain_0&hash=item3f07b8abee

Also using standard SD ReadWrite example.

Reads work well.

Problem is: when executing


myFile = SD.open("example.txt", FILE_WRITE);


SD card becomes fully corrupted - many broken files appears...

Please help.
Thanks.

robtillaart


There is too little information to help now, so

What library are you using?
Which Arduino?
How is the board connected?
What does the rest of your code looks like?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

tkbyd

The following may be helpful...

http://sheepdogguides.com/arduino/ar3ne1sd.htm

Even though it is couched in terms of a specific SD adapter, many general principles are addressed, and anyway- you can probably adapt the code to suit your adapter.

MarkT

Different SD cards use somewhat different FAT filesystems - perhaps your SD filesystem code has incomplete support?  It shouldn't be writing anything if it doesn't recognise the actual filesystem present on the card.  And the fact it reads suggests it does recognise it.
[ I won't respond to messages, use the forum please ]

flytroll

Hello!

Thanks for replies.

Lets me explain more detailed.

First of all Arduino - Duemilanove, 328
I'm using SD.h for communicated with SD card.

Wiring is:
CS - 4
MOSI - 11
CSK - 13
MISO - 12

SD card is formatted in vfat (msdos fat) Any other format doesn't allow to initialize card.

Results is:

1.
Code: [Select]

  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

...

  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // 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.println("error opening test.txt");
  }


works fine. I could save a file to SD card on my linux laptop and read it in Serial console.

2.
Code: [Select]

....
  myFile = SD.open("test.txt", O_CREAT | O_WRITE | O_APPEND);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
....


Doesn't work.
I need reformat card after this execution.

If you have any suggestions - please help.
I'm new in Arduino world.

grego

Hello,
Did you solve your problem? I have the same with the same reader.
Kind regards,
Grego

Go Up