Issues with SD storage

Hi there, i'm in serious troubles with the SD library. I'm working in the Storage team of a school project; we should manage to save some data in a SD, in a csv/txt file (plain text). We tried a few sketches from Arduino SD, and after a few edit we managed to save a few lines. Then the problem started. The further logs corrupted the SD card or produced some corrupted and incoherent datas (see pic) |500x94 Actually, the SD does not seem to be broken (it can be formatted with the PC and it works fine), but now we can't write anything on it. After a few reserch I found out that many people have problems, but there are only a few who solved them.

  • We don not use multiple SPI devices (but we use Serial)
  • We tried on an Uno and a Mega
  • Tested with 1 sec delay between data logs
  • We tried many different SD cards
  • Tested the SdFat lib with the same sketch
  • Tested a few SdFat lib examples, which always return SD card errors

This is the SD Module provided by the school. |281x500

Here the intrested part of the code:

  if(millis()-delta >= T_RUNTIME){ //Write every T_RUNTIME millis (1000)
    tempo = millis(); //long
    File dataFile = SD.open("datalog.csv", FILE_WRITE);
    
    if(dataFile){
        dataFile.print(tempo);
        dataFile.print(";");
        dataFile.println();
        dataFile.close();//!IMPORTANT
        delta = millis();
        Serial.println("Log OK");
    }else{
      Serial.println(F("Errore di scrittura"));
       }
  }

Yes, we do use "print" to write in the file. I read there are faster ways, but anctually I couldn't understand them.

How are you supplying the 3.3v for the module?

The Arduino 3.3v output pin can only supply 50ma and that is not enough to power the SD module. It looks like the module can accept a 5v input and has a voltage converter on the board. Try and power power it from the 5v pin.

Looks like an LC Studio SD module. These often fail.

Search this forum for LC Studio for topics like this.

"The Arduino 3.3v output pin can only supply 50ma" 150mA actually, but still not enough for an SD card. The board pictured does appear to have 5V regulator as noted. And resistor dividers for crappy signal level shifting.

And resistor dividers for crappy signal level shifting.

Actually they are pull-ups if it is an LC Studio card so the problem is no level shifters.

fat16lib:
Actually they are pull-ups if it is an LC Studio card so the problem is no level shifters.

I agree. I have similar modules and use the module’s 3.3V regulator output to power a CD4050 for level shifting. I apply power from the Arduino’s 5V rail to the module’s 5V input pin.

SD Card Circuit.JPG

Do not use CD4050 for this. Do use 74HC4050 instead..

pito: Do not use CD4050 for this.

Why not? If you're going to say this, you should do the courtesy of qualifying it with your reasons. This is well within spec for a CD4050, and it works perfectly.

Has been discussed many times in past. Compare the datasheets…

pito: Has been discussed many times in past. Compare the datasheets..

I just searched the forums using the search term "CD4050 SD Card" and found none of those discussions, (I read about the first 10 or 12 results). In fact, virtually every thread that I looked at recommended using the CD4050. That's why I used them myself - because everything that I'd seen recommended using one, (and I have heaps of them on hand). I've been running a couple of circuits using CD4050s 24 hours a day for a while now, and never had a bad read or write.

After looking carefully at the datasheet, I think I see what you're referring to - the CD4050 has pretty poor current sink/source characteristics. Still, it's well within spec for my SD card module. With my SD card module's 10K pullup resistors, the CD4050 has to sink 330uA to pull the lines low. According to the datasheet, at 3.3V a CD4050 can sink about 3.3mA at 25C, which drops off with temperature, to 2mA at 125C. The CD4050 is even worse at sourcing current, about 1mA at 25C, dropping off to about 0.5mA at 125C, but that shouldn't be a drama due to the pullup resistors. The chip only really needs to sink current, not source it.

So I still don't see a problem there. If you're referring to something else besides sink/source characteristics, perhaps you should clarify. Maybe a link to a couple of the threads you mentioned.

I have tried to supply with both 3.3 and 5V, the result is the same. That's why I thought it was a software issue. After a few intresting hours of web surfing, I read some people complaining for the low quality of this module, as fat16lib has pointed out. I've alredy bought one of theese microSD modules, which seems to have a logic level shifter to better interface with the SD card. Can you confirm it? Now a few more questions: does this MicroSD module works with the same software? It would be perfect, despite the fact it will probably arrive too late. However, the thing I learnt is that this should be an hardware problem, isn't it?

About what OldSteve and Pito are discussing, it beyond my abilities, i suppose. Thank you all!

The module you linked, the Catalex microSD module, does indeed have the level shifters. It works with the standard SD or SdFat libraries.

In some of the earlier versions of these modules there was a problem with multiple devices on the SPI bus, but this may have been fixed. If you have only this SPI device on the bus, there should be no problem.

Ok, thank you again. I forgot to say that this project should work in a cold ambient with low pressure, could it be a problem? Hope for the best, I'll let you know.

even cheaper is http://www.ebay.com/itm/161366316226