Go Down

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

airic

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:

Code: [Select]
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):

Code: [Select]
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.

ODwyerPW


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?
Quiero una vida simple en Mexico...nada mas.

mokwichi

#47
Nov 15, 2013, 06:27 pm Last Edit: Nov 15, 2013, 10:24 pm by mokwichi Reason: 1
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

rob91

#48
Feb 06, 2014, 12:28 am Last Edit: Feb 06, 2014, 06:49 am by rob91 Reason: 1
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:

Code: [Select]

#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:

Code: [Select]

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:

Code: [Select]

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!

ghlawrence2000

#49
Feb 24, 2014, 08:52 pm Last Edit: Feb 24, 2014, 08:54 pm by ghlawrence2000 Reason: 1

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

simonc319

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:

https://code.google.com/p/cte-lcd-modules-arduino-library/downloads/detail?name=CTE_DUE_shield.zip&can=2&q= .

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!


ghlawrence2000

#51
Feb 25, 2014, 06:44 am Last Edit: Feb 25, 2014, 07:08 am by ghlawrence2000 Reason: 1
Hi Simon,

Quote
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 http://arduino.cc/en/Reference/SPI 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"
Quote
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 :-

Code: [Select]
 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

simonc319

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

ghlawrence2000


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 https://code.google.com/p/sdfatlib/.

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.

Quote
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

ArduinoDetection

I have a Breakout Board for microSD Transflash from SparkFun (https://www.sparkfun.com/products/544) 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 http://21stdigitalhome.blogspot.com/2013/02/arduino-due-hardware-spi.html 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!

Code: [Select]
/*
  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
}


ghlawrence2000

Hi ArdunioDetection.
Quote
I have a Breakout Board for microSD Transflash from SparkFun (https://www.sparkfun.com/products/544) 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.

Quote
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!!

Quote
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?
Quote
You can look here for sdfatlib https://code.google.com/p/sdfatlib/.

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.

Quote
// 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

Go Up