I got an SD module that has 5V and 3.3V inputs and then got a schematic to be more sure that I don't smoke the thing and maybe my UNO as well.
Mfg site doc:
The module adopts a pop-up SD card interface, designeddouble interface, convenient for user design pinhole connection.
I requested docs and one thing I got is a schematic. What I see on the schematic is that MOSI, MISO and SCK all connect to 3.3V through a 10k resistor each. I am guessing that 5V on those lines from my UNO must voltage-divide through those resistors and that protects the can't-take-5V SD card.
Both the 5V and 3.3V power inputs go into an LM1117 3.3 chip, so that's safe.
If that's the way it works, does it qualify as level-shifting? Should I be putting resistors between my Arduino pins and this module?
This is a common problem with shields that are only half-designed. At least yours has
10K resistors in there. Would be nice to have a link so that others might see what
you're actually talking about....
Hint, hint.
A "series" resistor alone doesn't itself qualify as a level-shifter, you need a 2nd R to ground
to get a voltage divider. Likely what they're doing is using the clamping diodes inside the
SD Card [assuming it has them] to preclude blowing the I/O pins. Clamping diodes should
easily be able to handle (5V - 3.3V)/10K = 0.17 mA.
Sorry I can't link you to my email. Should I post someone elses' document on a sharing site? I don't think so, not if I want to get more such later on. But we can PM.
I understand enough to see what you mean by half-designed even as I see that what works, works. As long as what works won't quit due to load failure then I face the idea that doing the job with less resources may be the better design in this case, not as general practice.
I could try with small resistors in the signal lines between Arduino and SD module if there's a chance that 5V signals will reduce the life of the module. If I use too much, the UNO running at 5V won't see what comes back (I assume 3.3V comes back, a resistor may reduce digital 1 to 0.) so maybe I have no real option there.
Quote
The module adopts a pop-up SD card interface, designeddouble interface, convenient for user design pinhole connection.
This is obviously not English although it kind of looks like English. Likely Chenglish.
Here's what I would do.
a. try the module as is, it's probably ok if possessing said 10K R's as indicated.
b. "I could try with small resistors in the signal lines between Arduino and SD module" - I would definitely
NOT reduce the value of the 10K R's, unless also adding an appropriate R to gnd, and then I would use
something like 2.4K,4.7K voltage dividers in the SCK,MOSI,SS lines. In the MISO line, you don't want
a voltage divider since the output is only 3.3V as it is.
Hmmmm, so the maybe best route is to treat it as a 3.3V device which it should work as anyway.
The 10k resistors are surface mounts on the board, I couldn't change them if I wanted to though there are more than a few members here who could.
I think I will try at 5V but since it's late here and I don't do my best work tired, I'll send you a PM to get you that schematic if you would like.
This module is one of the simple ones. If I can't get it to work then I won't try any of the others but man oh man they have some interesting boards. And BTW, I paid $2.60 each for 3 of the things!
The schematic shows no diodes inline or out-of-line.
However after some agonizing I said to H with it and gave it a try just wired directly....
and met with painless success.
CS to 10
MOSI to 11
MISO to 12
SCK to 13
5V, 3.3V, grounds all straight over.
Running 0022 on a rev 0 UNO, imported SPI and SD libraries and first sketch just tested SD.begin() in setup() and got 1. Next step, check exists(), got 1. Then checked read and write, all good.
My Q&D code with some comments to make it look like I know what I'm doing.. hey, it works!
// Testing SD Module connected to Arduino UNO
// This UNO is running IDE version 0022
// Arduino SPI library and SD library are imported using the
// Sketch->Import Library pop-down menu. Both are standard.
// SD Lib reference: http://arduino.cc/en/Reference/SD
// This sketch looks for a file named text.txt and if it is
// present, tries to read and print the text. Then it tries to
// open a file named test.txt and write to that.
// The SD card used is formatted FAT, is FAT 16, FAT 32 may work.
// On mine I placed a text file named text.txt to test reading.
// Connections are all by direct female to male jumper wires
// No other hardware than SD Module with card, UNO and jumpers
// SD Module pin --- UNO pin
// 5V --- 5V
// 3.3V --- 3.3V
// GND --- GND
// GND --- GND
// CS --- 10
// MOSI --- 11
// MISO --- 12
// SCK --- 13
#include <SD.h>
#include <SPI.h>
byte state = 0; // controls what operation is run
byte flag = 0; // general use True/False
byte B; // single byte buffer
char fname[ 12 ] = "text.txt";
File sdfile; // File object
void setup(void)
{
Serial.begin( 9600 );
byte f = SD.begin( 10 ); // test if card is recognized
Serial.println( f, DEC ); // show success as 1, fail as 0
if ( !f ) while( 1 ); // if fail then sketch ends
f = SD.exists( fname ); // test if file text.txt is present
Serial.println( f, DEC ); // show success as 1, fail as 0
// if ( !f ) while( 1 );
Serial.println( "\nTime to do the data things.\n" );
}
void loop(void)
{
switch( state )
{
case 0 : // open text.txt for read if possible
{
sdfile = SD.open( fname, FILE_READ ); // try to open text.txt
if ( !sdfile ) // if test.txt not found, notify and change state
{
Serial.print( "Unable to open for read: " );
Serial.println( fname );
// while( 1 );
state = 2;
}
else
{
state = 1; // text.txt found, change to state 1
}
}
break;
case 1 : // read text.txt and print contents
{
if ( sdfile.available())
{
B = sdfile.read();
Serial.print( B );
}
else // once data is read, close file and change state
{
sdfile.close();
// while( 1 );
state = 2;
}
}
break;
case 2 : // now try to open/create test.txt for append/write
{
strcpy( fname, "test.txt" );
sdfile = SD.open( fname, FILE_WRITE );
if ( !sdfile )
{
Serial.print( "Unable to open for write: " );
Serial.println( fname );
while( 1 ); // sketch stops if reach here
}
state = 3;
}
break;
case 3 : // test.txt opened for append or created for write
{
for ( byte i = 'a'; i <= 'z'; i++ ) // append lowercase alphas
{
sdfile.print( i ); // append == add to end of what is there
Serial.print( i ); // this file grows with each new run
}
Serial.println( "\nOver-write start of file: " );
sdfile.seek( 0 ); // test ability to set write pointer
// unlike some seek() functions, this one starts at 0 instead of 1
// write over a-j with 0-9
for ( byte i = '0'; i <= '9'; i++ )
{
sdfile.print( i );
Serial.print( i );
}
Serial.println( "\nand that's all she wrote, goodbye!" );
sdfile.close();
while( 1 ); // sketch stops here
}
break;
}
}
My favorite tools are paint (mainly to "postprocess" screenshots) and notepad.
Copy the fixed font text, Paste here, Surround with ** **Teletype** **
[ t t ] marks, then trust in God and press Post.
Often, no edit is required.
This vendor even provides an Arduino connection scheme for the same SD card adapter.
(Recommend voltage dividers by resistors. They differentiate between Pin13 and others -- due to the led on Pin 13 ?)
Now, that one has the resistors wired in the right places, although it commandeers pin 10 for
SS, so you cannot stack it with other common shields.
The one thing I might do differently is place a 2.2K-3.3K R in series in the MISO line, so
if it is stacked with other shields, the 5V coming out their MISO lines won't blow this one.
I've requested they made a dual or quad SD module. You can only have 1 file open at a time per card so at least 2 to do both read and write with only 1 open and 1 close each should be faster?
But I've written enough software to think that 4 is a better if you deal with data.
The LC boards worked fine for me though Terry King hinted that they're marginal in a long term bad way.
I used the SPI library and the SDFat library, though the SD library worked fine too.
I made them work using IDE 0022 (only updated maybe less than a year ago, now at 1.05) and have had
no need to use one since.
The Examples in my IDE, under SD have code that worked for me. The code was the simple part.
I'm not sure that I should use my LC modules (cheaper in quantity) at all. I can make better voltage levelers anyway.
I've got it down to 5 resistors and 3 diodes in theory for VCC, MOSI, SCK amd SS. MISO and GND need no leveling.
The reason to have multiple cards is speed not lost on constant initialization on card deselect->select. It's major.