Go Down

Topic: SdFat for Due posted (Read 53026 times) previous topic - next topic

rochi2211

Good morning from Italy guys. There's no way to make it work. Can someone suggest me a tested "style" of micro SD adapter on Arduino due?

ninja2

#76
May 13, 2017, 03:36 am Last Edit: May 13, 2017, 11:43 am by ninja2
I doubt your problem is hardware and any 3V3 SD card will work if wired properly, and the sketch is written correctly. But to your question:

I have successfuly run a Sparkfun microSD shield on my Due but I had to do a little re-wiring on the shield as pins 11,12,13 do not support SPI on Due:

1) fold up pins 11,12,13 so they are not connected to Due
2) cut out shield above ICSP header so it is accessible from above shield
3) solder solid insulated wires (about 6cm long) into the plated through holes for pins 11,12,13. Strip the other ends and insert into ICSP as follows:
- pin D11 to ICSP pin 4 (MOSI)
- pin D12 to ICSP pin 1 (MISO)
- pin D13 to ICSP pin 3 (SCK)

(see photo attached)

My sketch is quite complex, but I've extracted & simplified the key parts that making the SD work for me:

Code: [Select]
#define CS_pin     8                  // Sparkfun microSD shield
.
.
#include <SPI.h>
#include <SdFat.h>
SdFat SD;
.
char logFileName[10] = "test1.csv";          // add 1 char for NULL terminator
.
.
void setup() {
  Serial.begin(115200);
  if (!SD.begin(CS_pin,SPI_FULL_SPEED)) {  // check SD is present & set to full speed
    Serial.println("[SD FAIL] STOP");            // tell the world if bad
    while(1) {}                                        // and stop forever
    }

  // SD is working OK so write a few data rows to it...
  logfile = SD.open(logFileName,FILE_WRITE);
  logfile.println("line1,cell2,cell3";
  logfile.println("line2,cell2,cell3";
  logfile.close();

}
 
void loop() {
// other stuff here
 }



rochi2211

sorry man, tried everything... now i'm trying to directly interface to an sd card but it doesn't work. May I try with something like soft spi? How can i do that?

ninja2

You've already been given a working solution. If you're not prepared to post your current code and details of your chosen hardware and wiring (e.g. diagram) then I can't help you

rochi2211

My friend there is only one possible wiring and the code is the example of both built in sd library and sdfat library as well. I tried 3 different modules everything is working on avrs. Is there any pin i should set as output? Is there something that has to be pulled low? The wiring is perfect, i'm getting mad at it

Go Up