Pages: [1]   Go Down
Author Topic: SD card write problem  (Read 1070 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

Rob Tillaart

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

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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:
....
  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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: