Arduino Forum

Products => Arduino Due => Topic started by: fat16lib on Dec 03, 2012, 07:30 pm

Title: SdFat for Due posted
Post by: fat16lib on Dec 03, 2012, 07:30 pm
I posted a version of SdFat with support for Due as SdFatBeta20121203.zip http://code.google.com/p/beta-lib/downloads/list (http://code.google.com/p/beta-lib/downloads/list).

Please read these files before using this version:

ArduinoDue.txt
changes.txt
readme.txt

There are a huge number of internal changes to improve support for Due, Teensy 3.0, and Mega so expect bugs.

Try the bench.ino example with a large buffer size.  Here are results for this low cost class 4 card http://www.newegg.com/Product/Product.aspx?Item=N82E16820171480 (http://www.newegg.com/Product/Product.aspx?Item=N82E16820171480).

I used a 32,768 byte buffer with a 20 MB file.
Quote

Free RAM: 62747
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 4159.07 KB/sec
Maximum latency: 21412 usec, Minimum Latency: 7651 usec, Avg Latency: 7867 usec

Starting read test.  Please wait up to a minute
Read 4390.18 KB/sec
Maximum latency: 12419 usec, Minimum Latency: 7415 usec, Avg Latency: 7462

Here are the changed defines for bench.ino
Code: [Select]

#define FILE_SIZE_MB 20
#define FILE_SIZE (1000000UL*FILE_SIZE_MB)
#define BUF_SIZE 32768
Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 04, 2012, 12:03 am
Thank you!

I'll test that! :D
Title: Re: SdFat for Due posted
Post by: stimmer on Dec 04, 2012, 12:24 am
Looking good - I've ran bench with the changed defines and no other changes on the cards I had. Two of them were with odd partitions initially.(they were bootdisks for a raspberry pi) I ran each test twice.

Code: [Select]


[MicroSDHC 4G class 2 in adapter, 56MB partition]

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 866.16 KB/sec
Maximum latency: 183747 usec, Minimum Latency: 31926 usec, Avg Latency: 37813 usec

Starting read test.  Please wait up to a minute
Read 2547.93 KB/sec
Maximum latency: 13355 usec, Minimum Latency: 12608 usec, Avg Latency: 12860 usec

Done

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 861.76 KB/sec
Maximum latency: 173563 usec, Minimum Latency: 32131 usec, Avg Latency: 38007 usec

Starting read test.  Please wait up to a minute
Read 2550.53 KB/sec
Maximum latency: 13337 usec, Minimum Latency: 12609 usec, Avg Latency: 12846 usec

Done


[MicroSDHC 16GB Ultra Class 1 in adapter, 56MB partition]

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2971.38 KB/sec
Maximum latency: 77963 usec, Minimum Latency: 9330 usec, Avg Latency: 11020 usec

Starting read test.  Please wait up to a minute
Read 3931.64 KB/sec
Maximum latency: 9612 usec, Minimum Latency: 8294 usec, Avg Latency: 8331 usec

Done

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2832.83 KB/sec
Maximum latency: 212444 usec, Minimum Latency: 9343 usec, Avg Latency: 11560 usec

Starting read test.  Please wait up to a minute
Read 3931.64 KB/sec
Maximum latency: 9606 usec, Minimum Latency: 8293 usec, Avg Latency: 8333 usec

Done


[Standard SD card, 1GB class 2, partitioned normally, but only 30Mb free space]

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 3157.74 KB/sec
Maximum latency: 202461 usec, Minimum Latency: 8545 usec, Avg Latency: 10354 usec

Starting read test.  Please wait up to a minute
Read 4111.16 KB/sec
Maximum latency: 9299 usec, Minimum Latency: 7892 usec, Avg Latency: 7969 usec

Done

Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 3041.00 KB/sec
Maximum latency: 238158 usec, Minimum Latency: 8458 usec, Avg Latency: 10751 usec

Starting read test.  Please wait up to a minute
Read 4112.86 KB/sec
Maximum latency: 8409 usec, Minimum Latency: 7897 usec, Avg Latency: 7964 usec

Done


[same MicroSDHC 4G class 2 in adapter as first test, but freshly formatted as one big FAT32 partition]

Type any character to start
Free RAM: 62747
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 1408.04 KB/sec
Maximum latency: 154868 usec, Minimum Latency: 19368 usec, Avg Latency: 23058 usec

Starting read test.  Please wait up to a minute
Read 3303.33 KB/sec
Maximum latency: 10479 usec, Minimum Latency: 9780 usec, Avg Latency: 9917 usec

Done

Type any character to start
Free RAM: 62747
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 1419.64 KB/sec
Maximum latency: 153552 usec, Minimum Latency: 19564 usec, Avg Latency: 22867 usec

Starting read test.  Please wait up to a minute
Read 3304.97 KB/sec
Maximum latency: 10541 usec, Minimum Latency: 9837 usec, Avg Latency: 9912 usec

Done



Incidentally I am using 6 inch flying leads from the SPI port into a breadboard and an SD breakout. No errors  :D
Title: Re: SdFat for Due posted
Post by: king44444 on Dec 04, 2012, 06:39 am
init failed for me using the sparkfun sd shield. The same sketch with the same shield worked fine with the UNO. Set SdChipSelect correctly and Tried SPI_HALF_SPEED and the other ones, but no luck. Not sure what I'm doing wrong.
Title: Re: SdFat for Due posted
Post by: DuaneB on Dec 04, 2012, 07:29 am
Hi,
    I tried a sheild a few days ago, It will not work as the SPI pins on the due are not connected through the normal digital pins as they are on UNO and MEGA, they are instead broken out through a six pin male head in the center of the board - see the pinout.

    I made a little adaptor to connect my sheild to this, for me this also did not work - I am guessing that it was down to the level shift IC on the breakout board which is designed to shift down from 5V to 3.3V, the due is already at 3.3 volt.

    The last thing I tried, was to solder jumpers directly to the SD Card and connect these to the SPI pins of the Due, this worked very well - it also means I can't easily connect my SD Card back to a PC, but that may or may not be a problem for you - it is not a problem in my application - as an alternative, you might be able to by pass the level shift IC on your breakout board.

The pin out of the SD Card is in a link in the

http://elasticsheep.com/2010/01/reading-an-sd-card-with-an-atmega168/ (http://elasticsheep.com/2010/01/reading-an-sd-card-with-an-atmega168/)

Duane B
Title: Re: SdFat for Due posted
Post by: fat16lib on Dec 04, 2012, 01:51 pm
king44444,

The SparkFun shield does not connect to the correct pins.  The SparkFun shield uses the ATmega168/328's standard SPI pins (digital 11-13), not the ICSP header.

See http://arduino.cc/en/Main/ArduinoBoardDue (http://arduino.cc/en/Main/ArduinoBoardDue).  Here is the key part:

Quote

SPI: SPI header (ICSP header on other Arduino boards)
These pins support SPI communication using the SPI library. The SPI pins are broken out on the central 6-pin header, which is physically compatible with the Uno, Leonardo and Mega2560. The SPI header can be used only to communicate with other SPI devices, not for programming the SAM3X with the In-Circuit-Serial-Programming technique.
Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 08, 2012, 02:59 am
Hi.

I can't initialize faster then SPI_DIV6_SPEED, but even with only this speed, I get double the speed in slideshow that I had previously. My tft is ITDB32WD (400x240), and I load a full image in 0.37s. Without DMAC, it tooks 0.70s.

Thank you very much!!!

But about speed, how do you have it wired to be able to handle 42Mhz?
Title: Re: SdFat for Due posted
Post by: fat16lib on Dec 08, 2012, 03:20 am
I have an SD socket connected directly to the SPI header with very short, under an inch, wires on a proto shield.

stimmer has this setup.
Quote

Incidentally I am using 6 inch flying leads from the SPI port into a breadboard and an SD breakout. No errors



Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 08, 2012, 01:35 pm
Ok, thank you.

I've one SD module somewhere, I'll wire it up to test it.

BR,

Joao
Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 08, 2012, 07:39 pm
Well, confirmed.

Wired directly to ICSP header on due I get full speed!!  :smiley-mr-green:

I getting from a Sandisk Extreme PRO (95MB/s):

Code: [Select]

Type any character to start
Free RAM: 62747
Type is FAT32
File size 50MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 4235.57 KB/sec
Maximum latency: 30782 usec, Minimum Latency: 7633 usec, Avg Latency: 7732 usec

Starting read test.  Please wait up to a minute
Read 4436.36 KB/sec
Maximum latency: 7791 usec, Minimum Latency: 7373 usec, Avg Latency: 7385 usec

Done


The best speed is obtained with 32k buffer.

I'm running slideshow now in 295mSec per picture, outstanding!!!  ]:D

Would it be to hard to implement the paralell mode in arduino? I don't mind to sacrifice the card reader to have it working this way!!! :D
Title: Re: SdFat for Due posted
Post by: fat16lib on Dec 08, 2012, 11:03 pm
I don't think the SDIO 4-bit mode can be implemented on Due.  It appears that I/O line PA21 is used to drive the TX LED.

The High Speed MultiMedia Card Interface uses PA21 for MCDA0, data line 0 of the SD.

I plan to play with 4-bit SDIO mode sometime in the future for SdFat. 

There are drivers for STM32F4 and I have an Olimex STM32-H407 so that may be first.  This is an amazing card for about $39 https://www.olimex.com/Products/ARM/ST/STM32-H407/ (https://www.olimex.com/Products/ARM/ST/STM32-H407/).

168 MHz, 1 MB Flash, 196 KB RAM



Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 09, 2012, 02:55 am
I agree, the specs are amazing! ;)

Ok, I just thought abut the 4 bit interface because it could be simpler and faster to implement.

I'll google on that to see what I get.

Thank you! ;)
Title: Re: SdFat for Due posted
Post by: fat16lib on Dec 09, 2012, 03:32 am
The 4-bit SDIO interface is usually not simpler to use than SPI.  

The protocol is propitiatory and only practical using the built in SDIO controller. With Due it appears you can't use the SDIO controller since one I/O line from the SDIO controller is used for the TX LED.

Using SDIO requires writing a new SD card layer since it is very different than the SD SPI protocol.

Title: Re: SdFat for Due posted
Post by: alvesjc on Dec 09, 2012, 11:44 am
Humm, ok, that's bad news. We have to stick with SPI then, ok.

Thank you for the info.
Title: Re: SdFat for Due posted
Post by: pito on Dec 12, 2012, 11:40 pm
Here is a measurement I did with SDIO on stm32f4 for block sizes 512b-32kB
http://arduino.cc/forum/index.php/topic,114027.msg858449.html#msg858449
Title: Sparkfun SDshield working with Due and SdFat !
Post by: gallegojm on Dec 14, 2012, 08:30 pm
I make the following connection between the Due and the Sparkfun SDshield:
Due        SDshield
--------   --------
Ground   Ground
3.3V       3.3V
D8          D8
MOSI       D11
MISO       D12
SCK        D13
(http://img9.imageshack.us/img9/8213/duesdshield.jpg)

It is working at full speed!!!
Here are the result with a Kingston 2 GB microSD card:
Quote
Type any character to start
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2224.90 KB/sec
Maximum latency: 721045 usec, Minimum Latency: 8101 usec, Avg Latency: 14716 usec

Starting read test.  Please wait up to a minute
Read 3954.20 KB/sec
Maximum latency: 9005 usec, Minimum Latency: 7940 usec, Avg Latency: 8286 usec

Done


Then I enable CRC checking (USE_SD_CRC set to 2 in SdFatConfig.h) and I modify bench.ino so that it loops for ever.
After more than 100 loops, I don't get any error
Quote
=========== Pass number 106 ===========
Free RAM: 62743
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 1268.47 KB/sec
Maximum latency: 370285 usec, Minimum Latency: 19459 usec, Avg Latency: 25752 usec

Starting read test.  Please wait up to a minute
Read 1686.36 KB/sec
Maximum latency: 20292 usec, Minimum Latency: 19243 usec, Avg Latency: 19429 usec

Done
=========== Pass number 107 ===========

I guess than, despite of large (and ugly) connections between the two cards, the buffer on the  SDshield help to reformat the signals.
Thank you fat16lib for your library!

Title: Re: SdFat for Due posted
Post by: dgelman on Jan 17, 2013, 11:27 pm
I am having trouble getting my card prepped for the DUE, I am using the SanDISK Extreme Pro 16 Gb (95Mbps)

Running QuickStart

Code: [Select]
Enter the chip select pin number: 10

Card successfully initialized.

Can't determine the card size.
Try another SD card or reduce the SPI bus speed.
The current SPI speed is: 10.50 MHz
Edit spiSpeed in this sketch to change it.


Running PrintBenchmark

Code: [Select]
Type any character to start
Free RAM: 95507
Can't access SD card. Do not reformat.
SD errorCode: 0X4,0XFF


Any ideas why this is the case?

Dan
Title: Re: SdFat for Due posted
Post by: alvesjc on Jan 18, 2013, 02:27 am
Hi!

How are you connecting the SDcard to Due?
Title: Re: SdFat for Due posted
Post by: dgelman on Jan 18, 2013, 05:50 pm
Lmao, yes..

I am using a similar stand lone like this:

http://arduino-direct.com/sunshop/index.php?l=product_detail&p=246

SS to pin 10 and everything else connected to the SPI header in the middle of the due.

Daniel
Title: Re: SdFat for Due posted
Post by: alvesjc on Jan 18, 2013, 05:58 pm
Ok, might be because of that chips and resistors.

Try to go to the lowest speed possible first.

If it works, start increasing until it fails.
Title: Re: SdFat for Due posted
Post by: dgelman on Jan 18, 2013, 06:09 pm
Hmmm, interesting, I changed it to EIGHTH speed and quickstart, benchmark and sdformatter all worked.  But that was the only speed that allows me.  I hope this is fast enough for my application.  How can I try and obtain a faster speed.  Perhaps the 6'' cables are too long.

Dan
Title: Re: SdFat for Due posted
Post by: alvesjc on Jan 18, 2013, 06:42 pm
If you reduce cabling, you might get close to 14Mhz. But with that resistors, you'll not move further then that.

I've used the sdcard in my tft also, and I've managed to get up to 28Mhz by removing the resistors and just put a shunt in their place.

The only way I've got 42Mhz, was with one sdcard reader like that with wires directly attached to the sdcard reader socket bypassing all the electronics there. Those electronics are for voltage translation and are very slow. Since Due is already 3.3V, you can safely bypass it.

I can place a picture here later for your reference.
Title: Re: SdFat for Due posted
Post by: dgelman on Jan 18, 2013, 08:57 pm
I think I am okay with the speed I have - I am just logging 2 byte numbers at 50Hz - so if I need the extra space, I will change the design.

Thanks :D
Title: Re: SdFat for Due posted
Post by: alvesjc on Jan 19, 2013, 02:24 pm
Hi.

Ok, that's up to you off course, I was just suggesting.

Anyway, the is the modded sdcard reader for Due.

(https://lh4.googleusercontent.com/-ztGg5EfQyJI/UPmgpXaW0MI/AAAAAAAACPM/XNtsNs0OYyk/s887/20130118_192025.jpg)

(https://lh4.googleusercontent.com/-S8dQ697xyNE/UPmgvwEI0EI/AAAAAAAACPU/gqVdwTOLsgs/s887/20130118_191955.jpg)

Regards,

Joao
Title: Re: SdFat for Due posted
Post by: sellensr on Jan 20, 2013, 03:11 am
Thanks for the work on the library! Here's first results from bench for an 8 GB PNY micro class 4 in the Adafruit micro SD breakout:

Code: [Select]
Type any character to start
Free RAM: 95415
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 85.27 KB/sec
Maximum latency: 159470 usec, Minimum Latency: 15 usec, Avg Latency: 1171 usec

Starting read test.  Please wait up to a minute
Read 1208.31 KB/sec
Maximum latency: 865 usec, Minimum Latency: 15 usec, Avg Latency: 81 usec



What were they thinking when they put the pins in the middle, right under the edge of the shield footprint? (I guess they were thinking minimum conductor length, and matching the original layout but not to accommodate existing shields that ignored the ICSP header...)

Here's the same card with 20 MB and 32768 Buffer at full speed.

Code: [Select]

Free RAM: 62747
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2074.35 KB/sec
Maximum latency: 452410 usec, Minimum Latency: 7830 usec, Avg Latency: 15788 usec

Starting read test.  Please wait up to a minute
Read 4381.52 KB/sec
Maximum latency: 12166 usec, Minimum Latency: 7413 usec, Avg Latency: 7476 usec


more details at http://rwsarduino.blogspot.ca/2013/01/usd-on-arduino-due.html including the connection system I rigged up for the Adafruit breakout board.
Title: Re: SdFat for Due posted
Post by: kamil_szczepan on Jan 23, 2013, 03:02 am
Hey Guys

I have LCD with SD card + shield for him + arduino DUE

the shield got this conection with sd card and due board

D_BUSY pin 7
D_CLK pin 6
D_CD pin 5
D_DIN pin 4
D_OUT pin 3
D_IRQ pin 2
F_WP pin 1 TX0
F_HOLD pin 0 RX0

Ok so, where i find pin definition in lib ?


Title: Re: SdFat for Due posted
Post by: thomasmue on Feb 09, 2013, 02:33 pm
Thanks for the libary and the pin maps.

I am a arduino noob and i managed to access the SD on the Due.
I use direct wires to a sd card socket and the following pin connections:









DUESDSPI
MOSICMDDI
MISODAT0DO
SCKCLKSCK
D10CD/DAT3CS
3.3VVDDVDD
GNDVSSVSS
GNDVSS2VSS2


I get this for a cheap 2GB san disk SD
Code: [Select]
Free RAM: 62747
Type is FAT16
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 3863.25 KB/sec
Maximum latency: 27974 usec, Minimum Latency: 7838 usec, Avg Latency: 8472 usec

Starting read test.  Please wait up to a minute
Read 4255.58 KB/sec
Maximum latency: 11905 usec, Minimum Latency: 7564 usec, Avg Latency: 7698 usec


and this for a 8GB Sandisk extreme Pro 95mb/s:
Code: [Select]
Free RAM: 62747
Type is FAT32
File size 20MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 4241.14 KB/sec
Maximum latency: 13791 usec, Minimum Latency: 7635 usec, Avg Latency: 7717 usec

Starting read test.  Please wait up to a minute
Read 4424.19 KB/sec
Maximum latency: 7806 usec, Minimum Latency: 7384 usec, Avg Latency: 7405 usec

Title: Re: SdFat for Due posted
Post by: jake1981 on Mar 13, 2013, 07:22 pm
I have a shield a screwshield for tft/sd with rtc from aqualedsource.com - rtc and tft and sd works perfectly. SD even on highest speed..

But when I put it all together, I cannot read time from RTC.. It's ds1307, and I am using https://github.com/adafruit/RTClib (https://github.com/adafruit/RTClib) as RTC library.
I think wire.h cannot be used together with sdfat library on Due's DMA mode..

Any solutions?
Title: Re: SdFat for Due posted
Post by: alvesjc on Mar 14, 2013, 03:30 pm
Hi Jake.

Well, if that is some kind of conflict between DMA and I2C, you can try the Henning Karlsen RTC library. I think it uses some kind of softI2C, it might work for you.

Give it a try.
Title: Re: SdFat for Due posted
Post by: jake1981 on Mar 16, 2013, 03:35 am
Thanks!

Nice library - I've combined it and RTClib, as I think RTClib was better expect it was using Wire.h and I'd rather go without..

Anyway, my bad and my apologies - it seems after all not to be SdFat that causes this, it's UTFT which makes sure RTC is in accessible.. Investigating further..
Title: Re: SdFat for Due posted
Post by: graynomad on Mar 16, 2013, 06:18 pm
@fat16lib

Quote
I plan to play with 4-bit SDIO mode sometime in the future for SdFat.

Any progress with this?

I'm designing a Due clone at present and wondering if I should incorporate the HSMCI interface to an SD socket.

______
Rob

Title: Re: SdFat for Due posted
Post by: fat16lib on Mar 16, 2013, 10:45 pm
It is unlikely that SdFat will support 4-bit SDIO on SAM3X since it won't work on Due.

I am reconsidering support for non Arduino boards.  I can't test unless I have a board and it's a lot of labor for a few users.

I have been playing with SDIO on STM32F4 for my own RTOS use.  SDIO provides super performance but you need large transfers with a lot of buffer.

I would be interested to know what Arduino applications would require more than a few MB/sec of I/O to an SD card.
Title: Re: SdFat for Due posted
Post by: graynomad on Mar 17, 2013, 03:32 am
Quote
I can't test unless I have a board and it's a lot of labor for a few users.

I understand, maybe I can bribe you with some hardware when the time comes :)

As for the number of users, that's in the lap of the Gods.

Quote
SDIO provides super performance but you need large transfers with a lot of buffer.

External RAM is supported, so buffer space should not be a problem.

Quote
I would be interested to know what Arduino applications would require more than a few MB/sec of I/O to an SD card.

That's probably the $64 question. I'm hoping to also have I2S support so maybe audio apps that analyse sound, a DSO that saves the waveform, logic analyser.

I guess I'm working on the "if you build it they will come" model, but they may not.

______
Rob
Title: Re: SdFat for Due posted
Post by: fat16lib on Mar 17, 2013, 09:41 pm
I wouldn't do anything to prevent  use of HSMCI.  I was very disappointed with Due.

All of these sound great:
Quote

I'm hoping to also have I2S support so maybe audio apps that analyse sound, a DSO that saves the waveform, logic analyser.

Title: Re: SdFat for Due posted
Post by: mjmes on Apr 30, 2013, 01:31 pm
I would like to experiment with the new system. But I am in the dark how you hook up an Arduino Due with an Sd card shield (I have a SEEED Studio SD card shield v 3.1). Could you please give me some details on how you do that?

Kindest Regards,
MJM
Title: Re: SdFat for Due posted
Post by: graynomad on Apr 30, 2013, 05:07 pm
How about a link to that shield?

In lieu of one I assume it uses SPI so you would connect it to the SPI pins and a CS pin of your choice on the Due.

One possible problem is that it may be designed for a 5v host and level shift the voltages, this may or may not work well with a 3v3 host.

Once again more information (and a schematic) of the shield would help.

_____
Rob
Title: Re: SdFat for Due posted
Post by: mjmes on May 01, 2013, 12:07 pm
The web site with only a description (no schematic) is http://www.seeedstudio.com/depot/sd-card-shield-p-492.html
There is no description of the connectors to this SD shield. It seems to me that a 6 pin connector on the arduino due (next to the processor chip) needs to be connected to the connectors on the SD shield. I don't know the name of these and at the store they couldn't help.  The 5V vs 3.3 V problem you mention could be solved with a jumper from the Due to the SD shield. Any ideas on the connectors and how to connect them?

MJM
Title: Re: SdFat for Due posted
Post by: graynomad on May 01, 2013, 04:55 pm
The first thing I see on that page is

Quote
Arduino and Seeeduino compatible ( Do not compatible with Mega)


That might be a problem :)

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
Title: Re: SdFat for Due posted
Post by: mjmes on May 01, 2013, 05:43 pm
Thanks, That is probably wise councel.

Kindest Regards,
MJM
Title: Re: SdFat for Due posted
Post by: stimmer on May 07, 2013, 03:00 am
There's an issue when SdFat and the VGA library are used together (see http://arduino.cc/forum/index.php/topic,150517.msg1226434.html#msg1226434)

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.
Title: Re: SdFat for Due posted
Post by: fat16lib on May 07, 2013, 04:44 pm
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.
Title: Re: SdFat for Due posted
Post by: eliman on May 08, 2013, 12:33 pm
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?
Title: Re: SdFat for Due posted
Post by: fat16lib on May 08, 2013, 05:10 pm
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:
Quote

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

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.
Title: Re: SdFat for Due posted
Post by: stimmer on May 09, 2013, 01:01 am
Yes that's too much of a compromise :-( 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.

Title: How do i connect to my DUE?
Post by: rohinrohin on May 31, 2013, 08:49 am
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
Title: Re: SdFat for Due posted
Post by: airic on Jul 24, 2013, 03:53 pm
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.
Title: Re: SdFat for Due posted
Post by: ODwyerPW on Nov 05, 2013, 05:34 pm

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?
Title: Re: SdFat for Due posted
Post by: mokwichi on Nov 15, 2013, 06:27 pm
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
Title: Re: SdFat for Due posted
Post by: rob91 on Feb 06, 2014, 12:28 am
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!
Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Feb 24, 2014, 08:52 pm

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
Title: Re: SdFat for Due posted
Post by: simonc319 on Feb 25, 2014, 06:04 am
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= (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 (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!

Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Feb 25, 2014, 06:44 am
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 (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
Title: Re: SdFat for Due posted
Post by: simonc319 on Feb 26, 2014, 03:02 am
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
Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Feb 27, 2014, 02:46 pm

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/ (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
Title: Re: SdFat for Due posted
Post by: ArduinoDetection on Aug 08, 2014, 01:37 am
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
}

Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Aug 08, 2014, 01:55 pm
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
Title: Re: SdFat for Due posted
Post by: derniwi on Jan 14, 2015, 10:38 pm
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:
Code: [Select]
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:
Code: [Select]
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
Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Jan 15, 2015, 06:39 pm
Shorten your connecting wires as much as you possibly can and try to use all the same length. I would expect this to allow you to be able to use SPI_FULL_SPEED and probably get rid of your random no card errors too.

Regards,

Graham
Title: Re: SdFat for Due posted
Post by: derniwi on Jan 16, 2015, 04:52 pm
Hi,

the wires length is about 20cm / 8 inches. I often get this problem also with SPI_HALF_SPEED.
The speed is currently not the big deal, I just try to get some data from the SD card.

The file SdInfo.h contains some constants for the SPI speed. Also with SPI_SIXTEENTH_SPEED I get errors...

Is the only way to get this work using short wires?

Best regards
Nils
Title: Re: SdFat for Due posted
Post by: pjrc on Jan 16, 2015, 05:31 pm
Is the only way to get this work using short wires?
Obviously short wires would be best.

If you can't do that, at least try to group the wires together closely, minimizing the area in the loop formed between any signal and the GND wires.  The ideal physical wiring is a GND wire tightly twisted with each signal, with all GND wires connected to the GND pins on both the Due and SD card.

The other thing you can try is adding series termination resistors on the 4 signals.  Values between 47 to 220 ohms are probably about right, though the specifics depend on the type and spacing of your wires.  The wire used in CAT6 cable is designed for exactly 100 ohms.

These issues are common with the WS2812 (aka NeoPixel) LEDs, where a digital signal from a pin is run quite some distance from the pin to the LED strip.  On my OctoWS2811 library page (http://www.pjrc.com/teensy/td_libs_OctoWS2811.html), scroll down to the "Signal Quality" section for more info, and some oscilloscope screenshots that show the issue with a real signal.
Title: Re: SdFat for Due posted
Post by: derniwi on Jan 18, 2015, 04:46 pm
@Paul: I have some "old" CAT6 wires (broken connectors or something like this) so it should be possible to use them for connecting and use 100 ohm terminator resistors? I haven't used term. resistors since I gave up using SCSI devices...  ;D
Title: Re: SdFat for Due posted
Post by: yoh-there on Jul 12, 2015, 08:23 pm
I would appreciate some help with the SdLibrary.

Software: I loaded it to the Due with the benchmark program, and set the CD pin to 10.

Hardware: MISO, MOSI, SCK are all connected to the proper SPI pins on the Due. it does NOT have level shifting, it only has 10K pull up resistors to the 3.3V bus. Also, while the card holder has it's own 3.3 volt regulator, I bypassed that and connected the 3.3 volt pin directly to the Due's 3.3 volt pin. Of course GND is connected, and CS to pin 10. All the wiring is short, can't be more than 3 inches.

While read latency seems ok (average 83 us), the write latency is horrific: 3470 us. Average write speed is under 30 KB/s.

The card is a run-off-the-mill 2GB Kingston card.

Any hints would be greatly appreciated!


Quote
Free RAM: 93235
Type is FAT16
File size 5MB

Buffer size 100 bytes

Starting write test.  Please wait up to a minute

Write 28.80 KB/sec

Maximum latency: 195699
 usec, Minimum Latency: 5                                                       
 usec, Avg Latency: 3470 usec                                                   
                                                                               
                                                                               
Starting read test.  Please wait up to a minute                                 
Read 1169.59 KB/sec                                                             
                                                                               
Maximum latency: 2741                                                           
 usec, Minimum Latency: 5                                                       
 usec, Avg Latency: 83 usec                 
Title: Re: SdFat for Due posted
Post by: ninja2 on Aug 21, 2016, 01:36 am
@SdFatLib: can you point me to the best of your libraries for Due, please sir.

I have found these but am not sure which to choose:

1) https://code.google.com/archive/p/beta-lib/downloads (https://code.google.com/archive/p/beta-lib/downloads)
This is only one I've found that includes ArduinoDue.txt but is a bit old? (June 2013)

2) https://github.com/greiman/SdFat-beta (https://github.com/greiman/SdFat-beta)

or is it now merged into your standard SdFafLib:

3) https://github.com/greiman/SdFat (https://github.com/greiman/SdFat)

or:

4) none of your libs support Due any more? :(

TIA
Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Aug 21, 2016, 02:43 pm
Option 3.

G
Title: Re: SdFat for Due posted
Post by: ninja2 on Aug 22, 2016, 12:22 am
tks G

Assuming I wire the SD correctly for DUE, should code that ran SD OK on a Mega work for Due without any modifications?

Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Aug 22, 2016, 12:37 am
Syntax wise there is no difference. But the DUE with sdfat has a clever DMA system that really helps speed things up somewhat!  8) ;D (As long as further down the road you don't also want to use Ethernet!)


G
Title: Re: SdFat for Due posted
Post by: ninja2 on Aug 22, 2016, 01:44 am
OK good.
Do I need to modify my code to get benefit of the DMA speed, or will it do that for me automagically using Mega code?
Title: Re: SdFat for Due posted
Post by: ghlawrence2000 on Aug 24, 2016, 12:06 am
No.

G
Title: Re: SdFat for Due posted
Post by: rochi2211 on May 08, 2017, 11:52 am
Hi! I've tried 3 different SD card socket . 2 are just SD card holders and one is a catalex module on 3.3. Nothing works and every connection is in its own place. Do I need something more to get the thing running on Arduino due? Thank you
Title: Re: SdFat for Due posted
Post by: ard_newbie on May 08, 2017, 02:33 pm
Follow this thread, reply #3 :

https://forum.arduino.cc/index.php?topic=411233.0 (https://forum.arduino.cc/index.php?topic=411233.0)

Title: Re: SdFat for Due posted
Post by: rochi2211 on May 08, 2017, 02:38 pm
Do you think it is library wise?
Title: Re: SdFat for Due posted
Post by: rochi2211 on May 08, 2017, 07:55 pm
Still having problems even with that library... Wiring is correct cs pin declaration as well wiring is as well short.... Maybe the module is faulty? Do you have a model for use with due?
Title: Re: SdFat for Due posted
Post by: ard_newbie on May 08, 2017, 08:19 pm

Check your wiring, it should be similar to the one in #reply 6 of this thread:

http://forum.arduino.cc/index.php?topic=266597.0 (http://forum.arduino.cc/index.php?topic=266597.0)


And declare pin 4 as an output if you use this pin as CS.
Title: Re: SdFat for Due posted
Post by: rochi2211 on May 09, 2017, 02:37 pm
sorry man, wiring is completely correct. I've tried 3 adaptors, declared cs pin as output, tried 3 differens micro sds. wire are short likely 10 cm. Nothing works. Am i orgetting somethig?
Title: Re: SdFat for Due posted
Post by: ard_newbie on May 10, 2017, 06:37 am

 You could find a tutorial for SD card reading in a document provided by EVTV Motor Verks: candueusermanual.pdf from page 39.
Title: Re: SdFat for Due posted
Post by: rochi2211 on May 11, 2017, 09:53 am
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?
Title: Re: SdFat for Due posted
Post by: ninja2 on May 13, 2017, 03:36 am
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
 }


Title: Re: SdFat for Due posted
Post by: rochi2211 on May 20, 2017, 10:34 pm
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?
Title: Re: SdFat for Due posted
Post by: ninja2 on May 20, 2017, 11:53 pm
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
Title: Re: SdFat for Due posted
Post by: rochi2211 on May 21, 2017, 10:24 pm
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
Title: Re: SdFat for Due posted
Post by: jlsilicon on May 07, 2018, 05:08 pm
What is the suggested SDCard Lib for the Arduino DUE ?
Title: Re: SdFat for Due posted
Post by: ninja2 on May 08, 2018, 04:00 am
the ordinary SdFat library works fine, same as for MEGA

(see my question at post #62 and answers following)
Title: Re: SdFat for Due posted
Post by: redou95100 on May 20, 2018, 02:40 pm
hello guys,

im trying to connect my sd card directly to my arduino due's spi header (like this http://www.instructables.com/id/Arduino-DUE-SD-Card/) but it doesn't work. I checked many times the wires. Here is a picture of what i did https://ibb.co/h0K938 . I tried the exemple cardinfo of the SD lib and i got init failed.

help please..
Title: Re: SdFat for Due posted
Post by: ard_newbie on May 20, 2018, 08:42 pm
There is a tutorial to fix some frequent SPI issues:

https://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps (https://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps)