Hi,
I am trying to interface a micro SD card with Arduino Mega and I have made all the connections properly.
For the logic level shif form 5v to 3v3, I am using a potential divider arrangement with 1k8 and 3k3 resistance. Each time I run the cardinfo code from the SD library I get "failed to initialize the card" message over the serial port.
PS. The card is formatted in FAT32 using SDformatter app as suggested in some posts. It is a 4 GB Transcend card. I have pulled up the CD pin of the SD card to 3v3.
What do you have connected?
Where is the uSD card power coming from?
Some cards need more than the 150mA the Mega's onboard regulator can supply.
Also the use of resistors makes for poor voltage dividers at SPI speeds, you may have to slow down the SPI speed.
CD is card detect, that is an output to the Mega that the software may or may not look at, usually looking for a low to tell the driver a card is detected.
I don't understand what you mean by 'what do you have connected' well I have only the SD card module hooked up to the SPI bus.
About this power issue I am using the mega 3v3 out.
Thanks for the information the current capacity is something I have to look into. I thought 150 mA was more than sufficient for the card.
I have added these lines (mentioned int the comment) to the card Info program to divide the clock speed. Please let me know if it is fine and whether this speed is ok for the resistance network.
#include <SD.h>
#include <SPI.h> // I added this line
// 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 = 4;
void setup()
{
setClockDivider(SPI_CLOCK_DIV32); // And this one.
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
If I am not mistaken the CD pin is for SD Interface and not for the SPI interface of the card. My module has a separate S SEL (slave select) pin. So I thought the CD was not needed, also by default it was pulled up in the module so I left it as such
I tried using the SDfat lib as you suggested. Here is the output I get by using the quick start code.
SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10
Enter the chip select pin number: 4
SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Is there a wiring/soldering problem?
errorCode: 0x1, errorData: 0x0
Restarting
Enter the chip select pin number:
I used an old computer SMPS to power the SD card with 3v3. It can supply up to 10A at 3v3. So the current being an issue is ruled out.
Also I made the SPI bus speed to SPI_QUARTER_SPEED in the example program.