ETH. SHIELD DFR0125 + DFRMEGA SD PROBLEM

Hi, im stuck testing a DFR0125 eth+sd shield V2.0 with an DFRMega V2.0 board, i don´t seem able to use the SD card ... so far i´ve tested changing the pinmode 53 to OUTPUT and HIGH and SPI CS to 8 and 4 but no luck, also tried with 2 different cards one formatted as FAT and the other as FAT32 ... so far i only get this on my serial monitor:
[b][i]Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card[/i][/b]
The code i am using is (On Arduino IDE 1.01):
[code]#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 8;
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("\nInitializing SD card...");
pinMode(53, OUTPUT); // change this to 53 on a mega
digitalWrite(53, HIGH);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}[/code]
Any help much appreciated!!!!
[b][i]Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card[/i][/b]
The code i am using is (On Arduino IDE 1.01):
[code]#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 8;
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("\nInitializing SD card...");
pinMode(53, OUTPUT); // change this to 53 on a mega
digitalWrite(53, HIGH);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}[/code]
Any help much appreciated!!!!
2012-11-28 19:48:11 Have you any other micro SD card in hand? I think use the FAT16 format is much better for Arduino maybe.
I will try it with my 2g micro SD card classic 4 later in this week also. Keep in touch!
Lauren
I will try it with my 2g micro SD card classic 4 later in this week also. Keep in touch!

2012-11-28 06:14:45 Hi, downloaded the library and tried one of the included examples (quickstart.pde) and again, can not connect to the card, reformatted the card using the SD Consortium SD FORMATTER and again, same ... any ideas?
here is the sketch im trying
[code]// Quick hardware test
#include <SdFat.h>
// Test with reduced SPI speed for breadboards.
// Change spiSpeed to SPI_FULL_SPEED for better performance
// Use SPI_QUARTER_SPEED for even slower SPI bus speed
const uint8_t spiSpeed = SPI_HALF_SPEED;
//------------------------------------------------------------------------------
// Normally SdFat is used in applications in place
// of Sd2Card, SdVolume, and SdFile for root.
Sd2Card card;
SdVolume volume;
SdFile root;
// Serial streams
ArduinoOutStream cout(Serial);
// input buffer for line
char cinBuf[40];
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));
// SD card chip select
int chipSelect;
void cardOrSpeed() {
cout << pstr(
"Try another SD card or reduce the SPI bus speed.\n"
"The current SPI speed is: ");
uint8_t divisor = 1;
for (uint8_t i = 0; i < spiSpeed; i++) divisor *= 2;
cout << F_CPU * 0.5e-6 / divisor << pstr(" MHz\n");
cout << pstr("Edit spiSpeed in this sketch to change it.\n");
}
void reformatMsg() {
cout << pstr("Try reformatting the card. For best results use\n");
cout << pstr("the SdFormatter sketch in SdFat/examples or download\n");
cout << pstr("and use SDFormatter from [url=http://www.sdcard.org/consumer.\n]www.sdcard.org/consumer.\n[/url]");
}
void setup() {
Serial.begin(9600);
cout << pstr(
"\nSD chip select is the key hardware option.\n"
"Common values are:\n"
"Arduino Ethernet shield, pin 4\n"
"Sparkfun SD shield, pin 8\n"
"Adafruit SD shields and modules, pin 10\n");
}
bool firstTry = true;
void loop() {
// read any existing Serial data
while (Serial.read() >= 0) {}
if (!firstTry) cout << pstr("\nRestarting\n");
firstTry = false;
cout << pstr("\nEnter the chip select pin number: ");
cin.readline();
if (cin >> chipSelect) {
cout << chipSelect << endl;
} else {
cout << pstr("\nInvalid pin number\n");
return;
}
if (!card.init(spiSpeed, chipSelect)) {
cout << pstr(
"\nSD initialization failed.\n"
"Do not reformat the card!\n"
"Is the card correctly inserted?\n"
"Is chipSelect set to the correct value?\n"
"Is there a wiring/soldering problem?\n");
cout << pstr("errorCode: ") << hex << showbase << int(card.errorCode());
cout << pstr(", errorData: ") << int(card.errorData());
cout << dec << noshowbase << endl;
return;
}
cout << pstr("\nCard successfully initialized.\n");
cout << endl;
uint32_t size = card.cardSize();
if (size == 0) {
cout << pstr("Can't determine the card size.\n");
cardOrSpeed();
return;
}
uint32_t sizeMB = 0.000512 * size + 0.5;
cout << pstr("Card size: ") << sizeMB;
cout << pstr(" MB (MB = 1,000,000 bytes)\n");
cout << endl;
if (!volume.init(&card)) {
if (card.errorCode()) {
cout << pstr("Can't read the card.\n");
cardOrSpeed();
} else {
cout << pstr("Can't find a valid FAT16/FAT32 partition.\n");
reformatMsg();
}
return;
}
cout << pstr("Volume is FAT") << int(volume.fatType());
cout << pstr(", Cluster size (bytes): ") << 512L * volume.blocksPerCluster();
cout << endl << endl;
root.close();
if (!root.openRoot(&volume)) {
cout << pstr("Can't open root directory.\n");
reformatMsg();
return;
}
cout << pstr("Files found (name date time size):\n");
root.ls(LS_R | LS_DATE | LS_SIZE);
if ((sizeMB > 1100 && volume.blocksPerCluster() < 64)
|| (sizeMB < 2200 && volume.fatType() == 32)) {
cout << pstr("\nThis card should be reformatted for best performance.\n");
cout << pstr("Use a cluster size of 32 KB for cards larger than 1 GB.\n");
cout << pstr("Only cards larger than 2 GB should be formatted FAT32.\n");
reformatMsg();
return;
}
// read any existing Serial data
while (Serial.read() >= 0) {}
cout << pstr("\nSuccess! Type any character to restart.\n");
while (Serial.read() < 0) {}
}[/code]
femur
here is the sketch im trying
[code]// Quick hardware test
#include <SdFat.h>
// Test with reduced SPI speed for breadboards.
// Change spiSpeed to SPI_FULL_SPEED for better performance
// Use SPI_QUARTER_SPEED for even slower SPI bus speed
const uint8_t spiSpeed = SPI_HALF_SPEED;
//------------------------------------------------------------------------------
// Normally SdFat is used in applications in place
// of Sd2Card, SdVolume, and SdFile for root.
Sd2Card card;
SdVolume volume;
SdFile root;
// Serial streams
ArduinoOutStream cout(Serial);
// input buffer for line
char cinBuf[40];
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));
// SD card chip select
int chipSelect;
void cardOrSpeed() {
cout << pstr(
"Try another SD card or reduce the SPI bus speed.\n"
"The current SPI speed is: ");
uint8_t divisor = 1;
for (uint8_t i = 0; i < spiSpeed; i++) divisor *= 2;
cout << F_CPU * 0.5e-6 / divisor << pstr(" MHz\n");
cout << pstr("Edit spiSpeed in this sketch to change it.\n");
}
void reformatMsg() {
cout << pstr("Try reformatting the card. For best results use\n");
cout << pstr("the SdFormatter sketch in SdFat/examples or download\n");
cout << pstr("and use SDFormatter from [url=http://www.sdcard.org/consumer.\n]www.sdcard.org/consumer.\n[/url]");
}
void setup() {
Serial.begin(9600);
cout << pstr(
"\nSD chip select is the key hardware option.\n"
"Common values are:\n"
"Arduino Ethernet shield, pin 4\n"
"Sparkfun SD shield, pin 8\n"
"Adafruit SD shields and modules, pin 10\n");
}
bool firstTry = true;
void loop() {
// read any existing Serial data
while (Serial.read() >= 0) {}
if (!firstTry) cout << pstr("\nRestarting\n");
firstTry = false;
cout << pstr("\nEnter the chip select pin number: ");
cin.readline();
if (cin >> chipSelect) {
cout << chipSelect << endl;
} else {
cout << pstr("\nInvalid pin number\n");
return;
}
if (!card.init(spiSpeed, chipSelect)) {
cout << pstr(
"\nSD initialization failed.\n"
"Do not reformat the card!\n"
"Is the card correctly inserted?\n"
"Is chipSelect set to the correct value?\n"
"Is there a wiring/soldering problem?\n");
cout << pstr("errorCode: ") << hex << showbase << int(card.errorCode());
cout << pstr(", errorData: ") << int(card.errorData());
cout << dec << noshowbase << endl;
return;
}
cout << pstr("\nCard successfully initialized.\n");
cout << endl;
uint32_t size = card.cardSize();
if (size == 0) {
cout << pstr("Can't determine the card size.\n");
cardOrSpeed();
return;
}
uint32_t sizeMB = 0.000512 * size + 0.5;
cout << pstr("Card size: ") << sizeMB;
cout << pstr(" MB (MB = 1,000,000 bytes)\n");
cout << endl;
if (!volume.init(&card)) {
if (card.errorCode()) {
cout << pstr("Can't read the card.\n");
cardOrSpeed();
} else {
cout << pstr("Can't find a valid FAT16/FAT32 partition.\n");
reformatMsg();
}
return;
}
cout << pstr("Volume is FAT") << int(volume.fatType());
cout << pstr(", Cluster size (bytes): ") << 512L * volume.blocksPerCluster();
cout << endl << endl;
root.close();
if (!root.openRoot(&volume)) {
cout << pstr("Can't open root directory.\n");
reformatMsg();
return;
}
cout << pstr("Files found (name date time size):\n");
root.ls(LS_R | LS_DATE | LS_SIZE);
if ((sizeMB > 1100 && volume.blocksPerCluster() < 64)
|| (sizeMB < 2200 && volume.fatType() == 32)) {
cout << pstr("\nThis card should be reformatted for best performance.\n");
cout << pstr("Use a cluster size of 32 KB for cards larger than 1 GB.\n");
cout << pstr("Only cards larger than 2 GB should be formatted FAT32.\n");
reformatMsg();
return;
}
// read any existing Serial data
while (Serial.read() >= 0) {}
cout << pstr("\nSuccess! Type any character to restart.\n");
while (Serial.read() < 0) {}
}[/code]

2012-11-28 01:18:48 I think the sample included in the sdfat library should work.
I remember I tested it on my SD card when the official library can't detect my card.
Lauren
I remember I tested it on my SD card when the official library can't detect my card.

2012-11-28 01:07:56 Hi, thanks for your reply.
Do you have any piece of code i can use to test that you´re sure to be working?
Regards
femur
Do you have any piece of code i can use to test that you´re sure to be working?
Regards

2012-11-28 00:31:23 1. The cs pin for the SD card should be D4.
2. I think you could try to use the sdfat library for Arduino. Here's a link.
[url=http://code.google.com/p/sdfatlib/downloads/list]http://code.google.com/p/sdfatlib/downloads/list[/url]
Hope it works. ;)
Regards,
Lauren
Lauren
2. I think you could try to use the sdfat library for Arduino. Here's a link.
[url=http://code.google.com/p/sdfatlib/downloads/list]http://code.google.com/p/sdfatlib/downloads/list[/url]
Hope it works. ;)
Regards,
Lauren
