Pages: [1] 2   Go Down
Author Topic: Interfacing SD card's to the Arduino and stability - a few tips.....  (Read 5913 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wanted to interface the arduino to a SD card. My method was to solder directly the wires to a micro sd connector for which any microsd card can be plugged. However i found that it was highly unstable with frequent SD errors. I corrected it by adding a 100uf and 0.1uf supply decoupling capacitors across pin's 3 and 4 of the sd connector. Now everything is stable at the maximum 8Mhz SPI bus speed using resistor voltage shifters. Even the SD card manufacturers recommend using capacitors, however few people use this which i think is the cause for many people commenting about unstable SD's. Keeping the wires short also helps as long wires act as stray capacitors ruining stability.

You can read more information about this at my blog post at http://kalum.posterous.com/sd-cards-and-arduino
I hope this information will help people trying to interface SD card's to the arduino.
Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1183
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks kalem,   I have been having some fun and games with an intermittent  SD card,   I halved its speed to solve my problem but I will I put another 100nF across 3&4 of the holder to make sure.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1473
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Caps often help and short wires are important.  Even with these precautions many people have problems with resistor level shifters.

I have done a study using cards with resistor level shifters.  I find that most older cards work at 8 MHz and almost all older cards work at half speed, 4 MHz.

Many newer cards fail at all speeds with resistor level shifters.  These cards expect very fast SPI signal rise times.  The SD spec requires a rise time of less than 10 ns for all clock speeds under 25 MHz.  It is just not possible to get sharp edges at 8 MHz into the typical capacitance with resistor level shifters.

New cards appear to use edge detectors.  New cards expect 5 ns rise times for 25 - 50 MHz clock.
Logged

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

Hello.
Can you or someone else post a scheme with 100uf and 0.1uf capacitors included?

Great article.
Logged

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

Can you or someone else post a scheme with 100uf and 0.1uf capacitors included?

Put them (at least the 0.1uF) between VCC & ground (pins 3&4 of the SD card). If you also use the 100uF be sure to check the polarity right. (short leg is ground, pin 3)
Logged

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

Thanks. Will try.
Logged

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

Caps often help and short wires are important.  Even with these precautions many people have problems with resistor level shifters.

I have done a study using cards with resistor level shifters.  I find that most older cards work at 8 MHz and almost all older cards work at half speed, 4 MHz.

Many newer cards fail at all speeds with resistor level shifters.  These cards expect very fast SPI signal rise times.  The SD spec requires a rise time of less than 10 ns for all clock speeds under 25 MHz.  It is just not possible to get sharp edges at 8 MHz into the typical capacitance with resistor level shifters.

New cards appear to use edge detectors.  New cards expect 5 ns rise times for 25 - 50 MHz clock.

Actually I am running the SPI bus at 8mhz (the maximum possible with a 16mhz AVR) using the above mentioned resistor based divider and it works ok. I am using the  new TwinMOS SDHC 4GB micro SD card and everything works fine. The SdFAT library benchmark test gives me 150K/sec write speed and 260k/sec read speed.  I tried a Sandisk 2gb card as well and it worked.  I will be willing to test any  new brand which has edge detectors to see if i can get them here.

Additional i would recommend that when buying SD cards for micro controllers to go for reputed names like TwinMOS, Sandisk, Kingston etc rather than cheap no-name brands.....SPI has to be implemented obligatorily for all SD cards but some no-name brands have rudimentary SPI support which is very slow and not optimised at all


Logged

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1473
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know that many SD cards work or appear to work with with resistor dividers but they are not as reliable as with IC level shifters and often users don't realize they have data errors. 

There is no CRC with SD cards on the Arduino so undetected errors are not uncommon.

I have written three SD card libraries for the Arduino.  SdFat, which is the basis for the "native SD library", Fat16, which is similar to SdFat with  a smaller memory footprint, and WaveHC, which is a library optimized for playing audio files.

These libraries have been downloaded over 25,000 times and problems with resistor based level shifters are one of the top problems people contact me about.

There is no guarantee that a given brand will have a good SPI controller.  In fact class 10 cards from top manufactures often have poor SPI performance since they are optimized for the 4-bit SD bus and are not expected to be used on the SPI bus.

Manufactures revised cards often without changing model numbers.  Performance of cards with the same model number may vary a great deal on the SPI bus.

Once again it is not possible to achieve the specified rise times requirements for SD cards with resistor level shifters driving the capacitance required by the spec.  Look at the signals on a good scope with a low capacitance probe.

This is why Adafruit replaced resistor level shifters with ICs in it's Wave shield and GPS shield and uses ICs in newer products.
Logged

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

Thanks for the insights again!

However, I can't seem to find the "real" solution for 5V to 3.3V interfacing. A lot has been posted, but it all seems a bit arbitrary and certainly not very simple to me. Apart from ready-made kits that (try to) solve this problem, do you have any ready and easy to use solutions or interesting reads or background information about this level shifting inconvenience?

Many thanks in advance!

Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23744
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Solution is to use a real chip to do it. Something like this perhaps
http://focus.ti.com/docs/prod/folders/print/cd4504b.html

Sparkfun had an SD shield with a chip like this (or maybe Motorola version), I'm not seeing it online now tho.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1473
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A 74AHC125N is a DIP and is used in Adafruit kits.  Here is the Data Logger Shield schematic http://www.ladyada.net/images/logshield/logschemv1.png.

I buy them here http://search.digikey.com/scripts/DkSearch/dksus.dll?lang=en&site=us&vendor=0&WT.z_cid=ref_findchips0311_dkc_buynow&mpart=SN74AHC125N.  They will ship First Class postage which is very low cost.

I have also used the 74HC4050N http://forums.adafruit.com/viewtopic.php?f=31&t=8738&p=51325&hilit=74HC4050N#p51325

SparkFun has uses a version of the 4050 hex level shifter in their microSD shield http://www.sparkfun.com/datasheets/DevTools/Arduino/microSD_Shield-v13%20Schematic.pdf. See http://www.findchips.com/avail?part=HC4050

Gravitech sells SD and MicroSD Card Adapters based on the 74LCX245 http://site.gravitech.us/MicroResearch/Others/SD-ADP/SD_ADP_Schematic.pdf.
« Last Edit: April 23, 2011, 12:21:24 pm by fat16lib » Logged

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

Will definitely look into that. Thanks a lot!
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23744
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ooh, nice fast switching times on the 74ahc125!
http://focus.ti.com/lit/ds/symlink/sn74ahc125.pdf

With the tristate output, it could be used as a level shifter by tie-ing the input low, put a pullup to 3.3V on the output, and enable the input to bring the output low, disable the input to let it go to 3.3V for the SD card high input.

If running from 3.3V supply, the inputs from the arduino should be limited to 3.3V as well, and not allowed to go to 5V which the sparkfun design seems to do.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...
With the tristate output, it could be used as a level shifter by tie-ing the input low, put a pullup to 3.3V on the output, and enable the input to bring the output low, disable the input to let it go to 3.3V for the SD card high input.
But a passive pull-up is not as efficient as using driven outputs.  (A fairly low value of pullup would be required to absolutely guarantee timing tolerances are met, and often we don't have good figures for capacitance of the circuits being driven.)  If you are going to use passive pull-ups, you might as well use the hokey resistive voltage dividers that some people use.

No, they just tie the enable low (so the output is always enabled) and they feed the signals through from A-Y.  They operate the 'AHC125 at Vcc = 3.3 Volts, and take advantage of the fact that the 74AHC125 inputs are 5-Volt tolerant.  Note that many chips, including 74HC125 (no 'A' in the middle of the part number) are not 5 Volt tolerant when they are operating at 3.3 Volts.  For the 'AHC125 note that maximum input voltage is specified to be 5.5V, not the Vcc+0.5V (or, maybe, Vcc+1.5V) that is typical for 3.3 Volt devices that are not 5 Volt tolerant.

For my money, I can't understand why (oh, why) anyone would use the '125 as a level shifter (even though it's not strictly illegal) when the '4050 chips are explicitly designed for level-shifting and buffering operating conditions.   (What happens when your purchasing agent, hoping to save a buck, orders 74HC125 instead of 74AHC125 parts?  Stranger things than that have happened.  Believe me.)  The last time I bought a few, the '4050s  were cheaper, too.

Oh, well...


Regards,

Dave
« Last Edit: April 23, 2011, 04:53:25 pm by davekw7x » Logged

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1473
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dave,

Here is my theory about use of the 125.  I modified an Adafruit kit using a 4050.  The 4050 is in a 16 pin DIP with two NC pins. I got it to "fit" by soldering wires to the pins and letting it float upside down above the board.  I convinced Limor at Adafruit that the mod solved SD reliability problems.

The 125 is in a 14 pin package and it just fits in the space where the resistor level shifter was so the rest of the board needs no mods.  I suspect that was at least part of the reason.  Only Limor knows why she used the 125.

It had to be a DIP since it is a kit for beginners.  Only three level shifters are needed but I couldn't find a simple part like the 4050 with fewer than 16 pins.  Do you know of one?
Logged

Pages: [1] 2   Go Up
Jump to: