SD card read/write with Arduino

I have played arround with LadyAdas code for a while, but as i was not able to set up the wiring right for it i could not really test it.. but what i noticed was quite a big overhead.. if i remember right it took quite a bunch of space on the arduino.. yet it seemed really good from its limitation/options.

Is the wiring not the same as the others? I haven't taken time to examine the schematic yet.

Hi all.

I'm back from a short break - I'm glad to see things happening.

The wiring should be the same for the ladyada code - the arduino's hardware SPI support works on a certain set of pins only. I tried my code out on a ladyada GPS board at dorkbot London a few weekends ago and it worked without modification.

As for using the ladyada code 'to get around the limitations of uFat' - well we're going full circle :wink: uFat is my way of getting around the limitations of having very little RAM and flash left after using the full FAT library..!

If your sketch is quite small and you can use the more fully featured library then I would suggest doing so as it makes your life really easy! uFat was designed for situations when this isn't quite the case :slight_smile: I've traded simplicity for RAM. A full sketch of uFat, MMC & deviceprint will use under 5k. You have to make compromises - this is a classic trade-off!

The DevicePrint code will work with anyone's library. You do need the arduino IDE version 0012/0013 though.

@JB - you're spot on. The file needs to be stuffed beforehand. And contiguous! Else strange results are going to happen :stuck_out_tongue:

@NachtWind -

If i look at your pics, especially those close-ups of your shield makes me realise that i need more than a few pins and cables to connect the card to the arduino..

The board there 'has a lot more than the requisite 6 resistors and a regulator' :slight_smile:

It also has a monostable multivibrator to drive an LED which flashes when there's a positive transition on the clock line. That accounts for about 6/7 components :smiley:

hehe, nice idea ^^

Well, i got mine to work at last and thats more than i had ever expected ;0)

Awesome!

Can I make a request?

It would be awesome to have a single post that has a schematic, a link to the library, and a small example sketch.

That way everyone could be confident they are on the same page.

Thanks again for everyone's efforts!

... or simply pushing the most needed infos to the playground?

Has anybody experimented with higher/lower resistor values in the voltage divider?

minimally different ones - i have used 3.3k and 1.6k, it still worked.

The voltage requirements at the MMC card inputs (MOSI, CLK, /SS) are defined in the MMC card product manual:

VDD in this case must be between 2.7 and 3.6v.

Input HIGH voltage:
min: 0.625 * VDD
max: VDD + 0.3

Input LOW voltage:
min: VSS - 0.3
max: 0.25 * VDD

As long as the voltage tapped off the divider falls within this range, all should be well.

The document to read is here:
http://www.sandisk.com/Assets/File/OEM/Manuals/ProdManRS-MMCv1.3.pdf

I've summarised all of this good stuff in a new thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235125412

I'm sure I've missed something :stuck_out_tongue:

All,

I had struggled with the DOSonCHIP module for a week or so. I stumbled upon this thread and uFAT2 solved all of my problems. Thanks to everyone who posted.

Just tried to download the library file on a Linux box using Firefox, and MediaFire promptly threw up by telling me to either sign in or use a supported browser (Internet Exploder?).

Read to the end or hop over here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235125412/
:slight_smile:

Hello everyone
Does anyone know to make the raw program write in blocks smaller than 512?

512 bytes is the sector size of the device.

Why do you want to write smaller blocks?

I'm trying to sample a guitar signal and store it to the SD card. It looks like when the Arduino writes the recorded signal to the SD card it takes up some time. Which means that the input signal gets ignored for awhile. I was hoping that if i could shorten the number of bytes being sent to the card it wouldn't ignore the sinput signal to a point that it wouldn't be noticed by the user. If this is to vauge I will gladly go into more detail later. Thanks for taking interest ::slight_smile:

I did find that I'm not setting high speed mode :-[

This might improve matters.

Another thing you might consider is setting up a 'double buffer' system, where you're reading values into one buffer under interrupt control whilst writing the other. You can tune the sampling rate so that you get a consistent period.

Another thing to do might be to break the 'write sector' function so that you can write bytes at a time... You'd have to re-send a command every 512 bytes or so, but that shouldn't take long - there's a latency of about 12 bytes as the write is finished up, then the next sector is primed.

Sorry if that all sounds quite complicated - but it has to be. You don't get something for nothing on a microcontroller :stuck_out_tongue:

Well to be honest i'm using the sd-raw program at the beginning of this thread so its notihng to do with your code. I have been following your code and will probably try to use it if I can't figure out my current idea. Thanks again you have been a big help to everyone here who is implementing sd to thier projects ;D

Thanks :slight_smile:

This procedure would likely be the same with whichever library you use. The SPI protocol for writing to the card goes like this:

  1. Send 'write sector command' - 0x58 a b c d 0x00
  2. Await command acceptance - ie you receive 0x00
  3. Send data token - 0xFE
  4. Send 512 bytes
  5. Send dummy checksum - 0x00 0x00
  6. Await 'done' status code - ie you receive 0x00

Mostly these 6 steps are all wrapped up in a function. What I suggest is that 1-3 are split out into one function, 4 in another, and 5-6 in yet another.

StartWrite() - does 1-3
WriteByte - actually would be the existing 'xfer byte' routine
EndWrite() - does 5 & 6

Start the write with steps 1,2,3.

Then write bytes at a time (step 4) until you've sent 512 of the blighters.

Do 5 & 6. If you want to continue, start again at the next sector with steps 1-3.

Let me know how you get on!