Arduino Due and SPI SD card (3.3V or 5V?)

Hi Everyone,

I've been battling with this problem for 2 days straight and tried many many things that I found in this forum and others from people that seem to have similar problems. Can't seem to find another way forward other than asking for help.

Ok so, my ultimate objective is to be able to use the SD card as a datalogger, but so far I'm yet to be able to initialise the SD card.

I'm using the SPI pins in the middle of the board for MISO, MOSI, and SCK. I'm using 3.3V for VCC and Ground for Ground. CS/SS I'm using pin 10 but I've tried many others such as 4, 6, 7, 53.

I also used a number of libraries such as SD.h, SDfat.h, etc

I also wasn't happy with my wiring on the breadboard as I think my breadboard/leads isn't very good and the connections aren't very "positive" so I've manually made cables as short as possible to connect the SD card module to the due pins as short as possible and with good connections. I have checked with a multimeter and the wiring seems good.

The SD card itself is probably good as I use it on a previous prototype for the same purpose using an Uno and keyes datalogging shield and works well. 32Gb formated to Fat32. It has a txt file in it that was written by the uno.

All example sketches from libraries that I tried fail to initialise the sd card. In particular the Quick Start Example sketch from the SDfat library gives an error that might be of help?

error Code: 0x43

I'm not expecting a quick fix, just would like to learn more and systematically test the system to figure out what I'm doing wrong or what component might be faulty. Also I'm sorry if I'm omitting some important info.

Thanks for the help

This might help:

A simple test sketch:

#include<SPI.h> 
#include<SD.h>    

#if defined (ARDUINO_ARCH_SAM)
#define ARDUINO_DUE
#endif

#define CSPIN 4   //slecting DPin-4 does not require to set direction
File myFile;      

void setup()
{
  Serial.begin(9600);
  SD.begin(CSPIN);        //SD Card is initialized
  SD.remove("Test1.txt"); //remove any existing file with this name
  myFile = SD.open("Test1.txt", FILE_WRITE);  //file created and opened for writing

  if (myFile)       //file has really been opened
  {
    myFile.println(4000);
    myFile.println(200);
    myFile.println(3000);
    myFile.close();

  }
  myFile = SD.open("Test1.txt", FILE_READ);  //file created and opened for writing

  if (myFile)       //file has really been opened
  {
    while (myFile.available())
    {
      Serial.print((char)myFile.read());
    }
    myFile.close();
  }
}

void loop()
{

}

Thanks for the reply ard_newbie, interesting reads but I'm only using and trying to make work this one SPI device, not multiples.

I tried your sketch but still no luck in finding the written file inside :/

Maybe this thread will be useful:

https://forum.arduino.cc/index.php?topic=138517.0

ard_newbie that's one of the first threads I've found and followed for my attempts and still no luck.

Ok so I had a bit of a breakthrough.

I managed to connect the same sd card reader to an arduino Uno on VCC 3.3V and no success, however, when I connect it to VCC 5V the sd card reader works, files are present, I can read/write etc.

So this tells me that in principle it's not a problem with the SD card module or the card.

It might mean that it needs 5V VCC but that can be complicated on the Due?

Also, maybe it didn't work on the uno on 3.3V because Uno needs 5v logic?

I feel really happy that something is working but would appreciate any help getting it to work with the Due.

Thanks

It seems that your SD card requires logic level shifters.

This breakout board has built in logic level shifters:

https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial/arduino-wiring

So the problem probably is that this particular sd card board needs 5V to work and the Due can't receive 5V logic otherwise it will get damaged right?

Is there any way around that without having to buy a new board or would be more hassle than just buying an sd board that is designed to work with 5V or 3.3V inputs?

Thanks for the help dude

Add logic level shifters (3.3V <-> 5V) such as this one:

You can also take a microSD adapter to SD and directly solder wires on it.
Then you connect them on your DUE card (3.3V).
No need for voltage adaptation.

The problem is probably the SD card module being used, I can't see any mention of which one it is, only that there is one. Given that it works with an Uno, it probably requires 5v for some level shifting (SD cards are 3v3!), which isn't needed on the Due, but this will cause it not to work. So, ditch the module which wasn't designed to work with the Due. If it's microSD, I'd do as taxodium suggests, if it's full size SD then you'll have to find a connector. You could probably mod the module, de-solder the components or cut a number of tracks then link across the board to give a direct connection between the header and connector.