SdFat for Due posted

The first thing I see on that page is

Arduino and Seeeduino compatible ( Do not compatible with Mega)

That might be a problem :slight_smile:

But without a schematic or some real information I don't know what to suggest except map out the schematic yourself from the PCB or buy a board from someone who does provide proper documentation.


Rob

Thanks, That is probably wise councel.

Kindest Regards,
MJM

There's an issue when SdFat and the VGA library are used together (see VGA library - now with TV output - #21 by system - Arduino Due - Arduino Forum)

I've been looking into this and the problem seems to be down to an SPI overrun. The VGA library is quite a DMA hog, and what appears to happen is that in spiRec() the TX DMA sends data faster than the RX DMA can write it to memory due to the bus contention.

Looking at the data sheet, the SPI_MR register has a flag SPI_MR_WDRBT which should hold up the TX DMA until the RX DMA has read the SPI_RDR register. I'm experimenting with the following fix:

in Sd2Card.cpp, in spiRec() around line 234
after this line: #if USE_SAM3X_DMAC
add this line: pSpi->SPI_MR |= SPI_MR_WDRBT;

in spiSend() around line 268
after this line: #if USE_SAM3X_DMAC
add this line: pSpi->SPI_MR &=~ SPI_MR_WDRBT;

The idea is that in spiRec() the SPI_MR_WDRBT flag helps keep the two DMA channels in sync, but spiSend needs the flag turned off again otherwise it will hang.

I have not given this fix much testing other than running bench and QuickStart, and a modified QuickStart which outputs to VGA, which all work correctly.

I am rearranging SPI into files for each processor so I will add the SPI_MR_WDRBT fix to SAM3X.

I will soon post this in an SdFat beta.

Hi
I followed that thread but i cant get it to work.
I am using Breakout Board for SD-MMC Cards: https://www.sparkfun.com/products/11403
I am confused about the pin connection.
what i did so far i connected:
D0 ===> MISO (ICSP-1)
CLK ===> SCK (ICSP-3)
CMD ===> MOSI (ICSP-4)
D3 ===> PIN 10
GND ===> GND
VCC ===> 3.3V

the rest of the ICSP pins are not connected

can anyone help me with schematic for this break board connection to the DUE?

I did tests with the SPI_MR_WDRBT bit set on SPI receive.

I used a 1 GB ATP industrial grade SD card which has SLC flash.

Setting the bit slows read a lot.

Here are results of bench with SPI_MR_WDRBT set in receive:

Free RAM: 79135
Type is FAT16
File size 10MB
Buffer size 16384 bytes
Starting write test. Please wait up to a minute
Write 3833.62 KB/sec
Maximum latency: 65578 usec, Minimum Latency: 3866 usec, Avg Latency: 4265 usec

Starting read test. Please wait up to a minute
Read 2993.18 KB/sec
Maximum latency: 5752 usec, Minimum Latency: 5457 usec, Avg Latency: 5472 usec

Here are the results with SPI_MR_WDRBT clear in receive.

Free RAM: 79135
Type is FAT16
File size 10MB
Buffer size 16384 bytes
Starting write test. Please wait up to a minute
Write 3832.15 KB/sec
Maximum latency: 65958 usec, Minimum Latency: 3864 usec, Avg Latency: 4267 usec

Starting read test. Please wait up to a minute
Read 4391.14 KB/sec
Maximum latency: 3956 usec, Minimum Latency: 3715 usec, Avg Latency: 3730 usec

Read is about 1,400 KB/sec slower with the bit set so I don't think I can justify setting the bit as the default.

Yes that's too much of a compromise :frowning: I've been experimenting with other flags and DMA settings and I can't get the lost speed back.

Also after modifying the bench example to output to the VGA library, it turns out that setting SPI_MR_WDRBT is slower than disabling DMA (#define USE_SAM3X_DMAC 0) when using both libraries together. There is no way I can find of getting the two libraries to share DMA without either SdFat going too slow or getting SPI underruns, or the VGA library getting visual glitches. Disabling DMA in SdFat is faster by about 50% (800KB/s v 1200KB/s) with no glitching.

NOOB ALERT
Hi,

Don't mind me asking this NOOBY question, but how do i connect my Arduino Due --> SD Card Shield?
Can i got the proper pin number and if req., any resistors?

Thanks for your help.

--
Rohin

Hello everyone,

I am trying to get this library functioning on the Arduino DUE with this LCD: http://imall.iteadstudio.com/im120419004.html and a custom shield. Everything is working fine on the MEGA.
As there is the option to use Software SPI (USE_SOFTWARE_SPI) I tried this because I have no option to connect to the SPI port on the DUE. But it is not working.

All I get is this:

Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0XFF

Here are my used pis (same as Arduino MEGA SPI):

SOFT_SPI_CS_PIN = 6
OFT_SPI_MOSI_PIN = 51
SOFT_SPI_MISO_PIN = 50
SOFT_SPI_SCK_PIN = 52

Does anyone has a tip for me? Speed is not important for me as I just want to save some configurations and settings.

Thanks,
A.

fat16lib:
I wouldn't do anything to prevent use of HSMCI. I was very disappointed with Due.
All of these sound great:

I know it's an older comment. Could you elaborate on what disappoints you specifically with DUE?

I have a custom made Arduino Due board with an SD shield attached to SPI( MOSI - Digital pin 75, MISO Digital pin 74, SCK, Digital pin76 and SS - Digital pin 4). I'd like to be able to log data to the SD as fast as possible, I have about 12KB/s of sensor data that I need to log. The sensors are samples at about 200Hz and provide about 50 bytes of data every sample.

I tried the Arduino SD lib but I found it too slow. I switched over to the SDFat lib but cannot get arduino to see the SD card. The SD library saw it just fine. My code as well as the example bench.ino seems to get stuck at the "if (!sd.begin(4, SPI_EIGHTH_SPEED)) sd.initErrorHalt();", no matter what speed I select. What am I doing wrong? Do I need to change my SPI pin settings somewhere in the SDFat lib code?

Please help....

Frank

Hi Everyone,

I also want to work the SdFat library. I´m using an Arduino Due and adafruits SD breakout shield.
I started the bench.ino and made the following changes:

#define FILE_SIZE_MB 20
#define FILE_SIZE (1000000UL*FILE_SIZE_MB)
#define BUF_SIZE 32768

I also use Pin 10 for the ChipSelect.
I have a 2GB Transcend SD which is FAT32 formatted.

This is what I got with SPI_FULL_SPEED:

Use a freshly formatted SD for best performance.
Type any character to start
Free RAM: 62751
Invalid format, reformat SD.

With SPI_HALF_SPEED I get:

Use a freshly formatted SD for best performance.
Type any character to start
Free RAM: 62751
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test. Please wait up to a minute
Write 1669.18 KB/sec
Maximum latency: 99601 usec, Minimum Latency: 16203 usec, Avg Latency: 19624 usec

Starting read test. Please wait up to a minute
Read 2315.89 KB/sec
Maximum latency: 14924 usec, Minimum Latency: 14013 usec, Avg Latency: 14147 usec

Done

Is there a reason, why I can`t run on FULL_SPEED?
Or has anybody a tip how to get a better performance?

Thank you!

rob91:
Is there a reason, why I can`t run on FULL_SPEED?
Or has anybody a tip how to get a better performance?

Hi Rob,

There is a possibility that your SD shield uses resistor level shifters, this appears to be the biggest stumbling block preventing successful use of SPI_FULL_SPEED, however, there is also the possibility that the SD card you are using might not be up to it?

I have a Fujifilm Class 4 SDHC 8GB card, and also a SanDisk Class 4 Micro SDHC 4GB card, both of which work successfully with the ColdTears(CTE) TFT/SD/TOUCH Shield.

For your own reference using your figures, 50MB file, 32768 buffer size, I get the following speeds :-

Fuji 8GB
Write 3100KB - 3320KB Read 3887KB - 3905KB
SanDisk 4GB
Write 3452KB - 3628KB Read 4320KB - 4338KB

I have a further point I would like to mention which although is not directly related to the sdfat library, I did notice the differences when running the sdfatlib benchmarks.

When compiled on IDE 1.5.4 the bytes written to flash was 22340 with #include <SPI.h> 22456
When compiled on IDE 1.5.5 the bytes written to flash was 22492 with #include <SPI.h> 22616
Furthermore, without the SPI library, free RAM is 62751 for V1.5.4 and 62751 for V1.5.5
however, with the SPI library, free RAM is 62703 for V1.5.4 but only 62699 for V1.5.5

The use of #include <SPI.h> in the above tests, did not demonstrate any noticeable differences in performance.

Conclusion :- V1.5.4 produces a smaller flash image and uses less RAM in certain cases, I no longer have older IDE's to continue this testing, has anyone else noticed any similar differences?

Regards,

Graham

Hi All,

I am very new to Arduino, and my first project with it requires read/write with an SD card; please bare with me if any of my questions appear generic.

I am currently using an Arduino Due and an 8GB microSD/microSDHC/microSDXC SanDisk card formatted in FAT32, in conjunction with a CTE TFT LCD/SD Shield with the specifications/schematics here:

Google Code Archive - Long-term storage for Google Code Project Hosting. .

I've tried doing an example from the Arduino site on read/writing to the SD card : http://arduino.cc/en/Tutorial/ReadWrite#.Uwv8IfldVxs . However I get an "initialization failed" error message from the code, which means that the DUE failed to write to the SD card. After reading several documentations, I suspect that pin 4 and 10 are indeed the right ports to read/write, but I could be wrong... I've also tried 53 which is the SS port on the Shield, which also didn't work.

I realize that DUE and this particular shield are new technology, but does anyone have any experience with this implementation? Thanks!

Hi Simon,

However I get an "initialization failed" error message from the code, which means that the DUE failed to write to the SD card. After reading several documentations, I suspect that pin 4 and 10 are indeed the right ports to read/write, but I could be wrong...

There "initialization failed" error message does NOT mean the DUE failed to write to the SD card, it did not even get past initialization.......

"I suspect that pin 4 and 10 are indeed the right ports to read/write", clearly you have misunderstood how SPI access to the SD card works, MISO/MOSI are the data in/out ports and are NOT pins 4 or 10. You should read up some more about SPI SPI - Arduino Reference but in a nutshell, the gist of it is this, you have a clock, data in and data out which go to ALL SPI devices, the only pin that changes and thus allows you to access a specific device is the CS(SS) pin

There are a couple of things you need to check.

Taken from "DUE_Shield_readme.txt"

Shipping default jumper configuration:

The TFT/SD Shield for arduino DUE is shipped with the following jumper config, if you use TFT modules in our store, you do not need to reconfig the jumpers.

LCD Vcc - 3.3V (JP2 shorted)
LCD backlight (LEDA+) - 3.3V (JP4 shorted)
arduino Pin32 to TP_DIN (JP10 opened)
On board SD - disabled (JP8 opened)

NOTE JP8 opened/on board SD - disabled. !!!!! Did you put a solder blob on JP8?

Assuming you did, the next thing to check is that you changed both entries relating to CS(SS) in your SD code :-

  Serial.print("Initializing 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);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

As a self-confessed newbie, did you pick up on the misleading error in the example??

pinMode(10, OUTPUT); & if(SD.begin(4)) { ??

The 10, and 4 relate to the same pin and therefor SHOULD at least be the same, in your case 53!

The coldtears shield is exactly what I have if you read the very post before yours, and it works fine with both SD and SDFATLIB once you bridge JP8, and use pin 53 as SS.

Best wishes,

Graham

Hi Graham,

Thanks for the suggestions. I would not have realized the need for soldering on JP8 or the what the code meant if you hadn't pointed it out for me. I've made a solder blob to enable JP8, and I also tried to use 4, 10, 52 and 53 to SS pin (keeping the numbers consistent for lines "pinMode(10, OUTPUT);" and "if(SD.begin(10))".) However I'm getting the same results as before... "Initialization failed." ...The only ideas I can come up with at the moment is that maybe my shield is busted, or perhaps I need a different library? I have SD.h for now, and I'm not sure how I can get SDfat library.

Please let me know if you have any more suggestions. Thanks again.

-Simon

simonc319:
I have SD.h for now, and I'm not sure how I can get SDfat library.

Please let me know if you have any more suggestions. Thanks again.

-Simon

Hi Simon,

You can look here for sdfatlib Google Code Archive - Long-term storage for Google Code Project Hosting..

The only other comments I have is that there is always the possibility the SD card you are using is a bit naff? I had a cheap ebay job that would not work with SD.h but did work with sdfatlib at slow speed.

Finally, did you try the 'CardInfo' example? This should tell you at least that the card is detected and wiring is correct, it will also initialize with SPI_HALF_SPEED by defualt, which will go some way towards proving if the SD card is not so good.

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3518857216
Volume size (Kbytes): 3436384
Volume size (Mbytes): 3355

Files found on the card (name, date and size in bytes):

You do NOT need to bother 'trying' 4,10,52 as your SS pin...............on the coldtears shield it IS 53 !! PERIOD.

If this still does not help you, beg/steal/borrow a different SD card, preferably SanDisk, Transcend, Kingston ..... even only 1GB or 2GB at least until you are confident of your hardware and software arrangement.

Regards,

Graham

I have a Breakout Board for microSD Transflash from SparkFun (SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics) and I am trying to connect it to the Arduino Due I just bought.

I read this entire forum and countless others and still can not figure out what i am doing incorrectly. I connected the DO (MISO), SCK, and DI (MOSI) to the correct pins on the SPI 6 pin male connector. I used The 21st Century Digital Home: Arduino Due Hardware SPI to configure the pins.

I also attached my chip select (CS) to digital pin 52 to make use of the extended SPI.

5V into Vcc and GND into GND. CD is not connected on my breakout board.

I just used the standard READWRITE example for the SD that comes preloaded in the arduino IDE.

Can someone please explain why I am getting "initialization failed"?? Purely from the print statements that it is because SD.begin(52) does not work. I am confused by this. However, I tried so many more digital pins because lots of people said it doesn't matter, but no luck.

Please help!

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

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

File myFile;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing 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(52, OUTPUT);

  if (!SD.begin(52)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
  // nothing happens after setup
}

Hi ArdunioDetection.

I have a Breakout Board for microSD Transflash from SparkFun (SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics) and I am trying to connect it to the Arduino Due I just bought.

Those things are notoriously difficult to get working first time, especially if you are new to all of this! The first and most common problem is connecting wires that are too long, and personally I like the to have the wires the same length too.

5V into Vcc and GND into GND

????????!!!!!!! 5V into Vcc!!!!!!!!!???????

You may actually have destroyed your SD card..... You SHOULD NOT be using 5V with an SD card!! They are all 3.3V for supply and signal level!!

I read this entire forum and countless others and still can not figure out what i am doing incorrectly.

You read this entire forum but chose to ignore my post immediately prior to yours?

You can look here for sdfatlib Google Code Archive - Long-term storage for Google Code Project Hosting..

The only other comments I have is that there is always the possibility the SD card you are using is a bit naff? I had a cheap ebay job that would not work with SD.h but did work with sdfatlib at slow speed.

Finally, did you try the 'CardInfo' example? This should tell you at least that the card is detected and wiring is correct, it will also initialize with SPI_HALF_SPEED by default, which will go some way towards proving if the SD card is not so good.

One final comment, I notice from your code you commented out the pinmode statement.

// or the SD library functions will not work.

//pinMode(52, OUTPUT); <---------- ?? Uncomment this!!!

if (!SD.begin(52)) {
Serial.println("initialization failed!");
return;

Assume your SD is now dead after its exposure to 5V, so test in another device or get another card before you go any further.

Try my suggestions, and post back how you get on.

Regards,

Graham

Hi,

I've just tried bench.ino from the SDFat Beta (Dec. 2014) and using a simple SD card module from Ebay and also an Arduino Due. The SD card is a Transcend 16GB Class 10 formatted with FAT32 using the SD formatting tool from sdcard.org, but copied some file on it.

I just can use the SPI_HALF_SPEED, I'll get errors with SPI_FULL_SPEED.

This is the result:

Free RAM: 94075
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)

Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Version: 8.0
Serial number: 0X80E4DD27
Manufacturing date: 8/2014

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
375.92,58303,798,1354
372.03,38391,1072,1367
372.06,38406,1058,1367
370.59,38381,1055,1372
371.14,39037,1059,1370
371.14,38390,1056,1370
371.64,38387,1071,1368
371.06,38388,1071,1370
370.70,39672,1059,1371
371.42,38398,1057,1368

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1178.89,866,423,432
1178.89,867,415,432
1178.61,866,416,432
1178.61,867,416,432
1178.61,867,416,432

Done

But sometimes when I start the sketch I'll get this error:

Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0

without changing anything. Turning off the Arduino IDE and the Arduino (cycle power) may fix this problem.

Any idea?

Best regards
Nils