SDuFAt With Arduino Mega (1280 or 2560)

I am currently trying to get SD card reading to work on my Arduino Mega. I currently have both Mega models to test on (the 1280 & the 2560).

The adapter I'm using for my SD card is this one http://iteadstudio.com/store/index.php?main_page=product_info&cPath=3&products_id=55&zenid=uqe03c4n47l2o82i8g47ubq563 With this shield to couple it to the Mega http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=231

I am using the library, SDFAT

http://code.google.com/p/sdfatlib/downloads/list

I have modified the SD2pinmap.h lines 41 to 45 to this

// SPI port
uint8_t const SS_PIN = 49;      // SC 53 or 49???
uint8_t const MOSI_PIN = 52;    // data out
uint8_t const MISO_PIN = 50;    //data in
uint8_t const SCK_PIN = 51;     // CLK

I am trying to get the example SDfatinfo.pde to work, and modified the code from line 148 to 150.

pinMode(53, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(53, HIGH);                    // but turn off the W5100 chip! (not applicable)
  uint8_t r = card.init(SPI_HALF_SPEED, 53);  // Use digital 53 as the SD SS line

Running the gets this reply in the serial monitor (comments were added manually and are the different cards

//32MB Cannon 

card.init failed
SD error
errorCode: 2
errorData: FF

type any character to start

//2nd 32MB Cannon

card.init failed
SD error
errorCode: 2
errorData: FF

type any character to start

//128MB Kodak

init time: 344

Card type: SD1
readCID failedSD error
errorCode: F
errorData: FF

type any character to start

//2BG Kingston MicroSD+adapter

init time: 624

Card type: SD2
readCID failedSD error
errorCode: E
errorData: FF

type any character to start

//4GB PNY SHDC microsd+adpater

init time: 359

Card type: SDHC
readCID failedSD error
errorCode: E
errorData: 1F

Can someone help me pinpoint why I can't read the info of any of the cards?

I am also having this exact problem. Can anybody help this guy? Fixing his problem would fix mine. ;)

no sd card

card.init failed
SD error
errorCode: 1
errorData: 0

type any character to start

I have spent an hour looking for furthur documentation on this and have found none.

I spent another hour using my minimal experience looking through the code in the libraries trying to find where the error codes come from and have only found a headache.

Could any of you guys who are more experienced take a look at this as I really am just as frustrated and lost as OP. [smiley=undecided.gif]

Thank you much Richard Crowley. Yet another reason to not debug at 4am. Mine is a 32MB Cannon and threw the same errorcode: 2 that dwjp902 got. Dunno how I missed that, but here it is for Dwjp902.

//32MB Cannon
errorCode: 2 /** CMD8 was not accepted - not a valid SD card*/
errorData: FF
//your card is probably too small or not configured correctly.


//2nd 32MB Cannon
errorCode: 2 /** CMD8 was not accepted - not a valid SD card*/
errorData: FF
//your card is probably too small or not configured correctly.


//128MB Kodak
errorCode: F /** timeout while waiting for start of read data */
errorData: FF
//try doing a FULL FORMAT and maybe increase the value of [uint16_t const SD_READ_TIMEOUT = 300;]


//2BG Kingston MicroSD+adapter
errorCode: E /** read CID or CSD failed */
errorData: FF
//no idea what this means. need to research.


//4GB PNY SHDC microsd+ adapter
errorCode: E /** read CID or CSD failed */
errorData: 1F
//no idea what this means. need to research.

ALSO, I noticed the following in SdCard.h

// define software SPI pins so Mega can use unmodified GPS Shield
/** SPI chip select pin */
uint8_t const SD_CHIP_SELECT_PIN = 10;
/** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = 11;
/** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = 12;
/** SPI Clock pin */
uint8_t const SPI_SCK_PIN = 13;

I suggest you change that to this:

// define software SPI pins so Mega can use unmodified GPS Shield
/** SPI chip select pin */
uint8_t const SD_CHIP_SELECT_PIN = 53;//10;  53 or 49?
/** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = 52;//11;
/** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = 50;//12;
/** SPI Clock pin */
uint8_t const SPI_SCK_PIN = 51;//13;

Hi, I have the same problem with an LCD Module (this) http://iteadstudio.com/store/index.php?main_page=product_info&cPath=3&products_id=55 and the shield (this one) http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=149

Any solution ¿?

Yeah, I'm using the 3.2" version of that screen (http://iteadstudio.com/store/index.php?main_page=product_info&cPath=3&products_id=54&zenid=0cdtc1ifuchgll0puj502vfgq2) with the MEGA shield v1.1 (http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=231) and struggling to get the SD part to work.

This isn't the first thread I have seen on this topic either. Usually the thread just dies after a while with no clear resolution. As soon as any of us get that thing working, please share a link to the library for download + how you made it work and/or a modified version of the library for simplicity. Solve this issue once and for all!

(Sorry for my English is not my native language) Ok. I'm working with this problem and trying different libraries, etc.

If i get work this shield , I share it!!! of course.

I got it to work, I changed the speed value to 1/4

pinMode(53, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(53, HIGH);                    // but turn off the W5100 chip! (not applicable)
  uint8_t r = card.init(SPI_QUARTER_SPEED, 53);  // Use digital 53 as the SD SS line

and the info returned this

type any character to start

init time: 968

Card type: SD2

Manufacturer ID: 2
OEM ID: TM
Product: SA02G
Version: 0.3
Serial number: 1411765916
Manufacturing date: 5/2009

cardSize: 3854336 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

part,boot,type,start,length
1,80,6,63,3854273
2,0,0,0,0
3,0,0,0,0
4,0,0,0,0

Volume is FAT16
blocksPerCluster: 64
clusterCount: 60215
fatStartBlock: 71
fatCount: 2
blocksPerFat: 236
rootDirStart: 543
dataStartBlock: 575
Data area is not aligned on flash erase boundaries!

I formatted the SD card with this http://www.sdcard.org/consumers/formatter/ to remove the partition error.

Info returns this now.

type any character to start

init time: 401883

Card type: SD2

Manufacturer ID: 2
OEM ID: TM
Product: SA02G
Version: 0.3
Serial number: 1411765916
Manufacturing date: 5/2009

cardSize: 3854336 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

part,boot,type,start,length
1,0,6,135,3854201
2,0,0,0,0
3,0,0,0,0
4,0,0,0,0

Volume is FAT16
blocksPerCluster: 64
clusterCount: 60214
fatStartBlock: 136
fatCount: 2
blocksPerFat: 236
rootDirStart: 608
dataStartBlock: 640

type any character to start

Running the LS example with the modified quarterspeed, 53 line returns this

Type any character to start
Free RAM: 6942
Volume is FAT16

Files found in root:
128661~1.PNG  2010-10-09 04:31:54 306078
128902~1.JPG  2010-11-06 04:41:46 441175
EST.TXT       2010-11-21 04:25:44 0

Files found in all dirs:
128661~1.PNG
128902~1.JPG
EST.TXT

Done

It works!

There were only tested SPI_HALF_SPEED.

Thank you so much