SD card level shifting using 74HC125 IC

Hi there.

I'd like to add SD Card to an Arduino without using a shield/board.

I use 74HC125 to do the level shifting.

Pin 1,4, 7 and 10 are connected to ground. Pin 14 , 12, 13 are connected to 3.3 V. Pull up resistor is connected to the 5V pin on the Arduino. SD card's power pin is connected to the 3.3 V pin on the Arduino.

When I try to run SD card test program it says there is a problem with wiring or chip select pin.

I think according to this connection, I should select chip select pin as 10. But despite many attempts I shouldn't be able to run this program successfully.

Any ideas what might be the problem ?

Also I made my own SD breadboard adapter.

The thing that comes to my mind is may be there is a disconnection in home made breadboard adapter.

Or may the 74HC125 chip may have an ESD damage ?! There are two power rails connecting to the breadboard. One is 3.3 V the other one is 5V. Ground's are connected. When I try to measure the voltage between + rail of 3.3V and ground, instead of 3.3V I measure about 4.2 volts. Is it normal?

Any help would be appreciated. Thanks.

From the example:

        ** CS - depends on your SD card shield or module. 
        Pin 4 used here for consistency with other Arduino examples
.
.
.
        // change this to match your SD shield or module;
        // Arduino Ethernet shield: pin 4
        // Adafruit SD shields and modules: pin 10
        // Sparkfun SD shield: pin 8
        const int chipSelect = 4;

Here is the actual circuit on the breadboard.

Here is the example program which I try to run.

/*
  SD card test 
   
 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.
 	
 The circuit:
  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module. 
 		Pin 4 used here for consistency with other Arduino examples

 
 created  28 Mar 2011
 by Limor Fried 
 modified 16 Mar 2011
 by Tom Igoe
 */
 // include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;    

void setup()
{
  Serial.begin(9600);
  Serial.print("\nInitializing 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);     // change this to 53 on a mega


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present."); 
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {
  
}

After uploading program to Arduino it says:

Initializing SD card...initialization failed. Things to check:

  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?

I changed chip select pin values to 4, 10 and 8. But still program gives the same error.

Also when I measure voltage between 3.3 volt rail and ground it is 4.28 volts. This confused me a bit. Shouldn't it be 3.3 volts.

Your diagram has no ground wire from the Arduino to the breadboard. Is that just an error in the diagram?

The rest of the circuit looks O.K. at least from my quick glance. I may have missed something since it was a quick look.

I would next suspect the home made SD adapter.

Chip select should be pin 10 for this setup.

fat16lib:
Your diagram has no ground wire from the Arduino to the breadboard. Is that just an error in the diagram?

Sure. I updated the diagram.

Or if I somehow zap the chip with static electricity may it be the reason why the circuit doesn't work.

Thanks for the explanations.

Your sketch still has the CS pin set to 4, but your wiring is using pin 10. See a problem there?

Some large breadboards have the power supply rails isolate 1/2 way.
Ensure you have continuity the full length on the 4 long rails.

I updated the chipSelect pin to 10. Also power rails are not split into two parts in my breadboard.

After playing around a little bit and using resistors instead of 74HC125 IC I saw another message: "Could not find FAT16/FAT32 partition. Make sure you've formatted the card"

So as fat16lib mentioned I suspect that there is a disconnection in the home made SD adapter.

I ordered a SD/MMC card holder and a few spare 74HC125 IC chips. I will solder the 8 large leftmost pins of the holder to the corresponding wires.

Hopefully it works as expected this time :wink: