>> Resolved << : MEGA with cardinfo.h and "LC studio" SD card reader dont work

The same in French at (Le même en Français à) >> Résolu << : MEGA + lecteur de carte SD "LC studio" ne fonctionnent pas... - Français - Arduino Forum

Hi every body,

When I started to work on this SD card reader, I thought to have 15 minutes to start to learn all the functions of the library (SD in the case).
Perhaps is there something I don't understand but nothing is correctly going on.

I m working on MEGA with an "LC studio" SD card reader.

If you read French, U can see this post (in FRench) : http://arduino.cc/forum/index.php/topic,125710.0.html

I m tring now to expose the problem here.

At every time I open the serial monitor, MEGA send this message :

Initializing SD card...initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

The program in the ATMEGA2560 of the MEGA is the one you can find by : Files/Exemples/SD/cardinfo of the 1.0.1 ARDUINO version. I modified it to fit well to MEGA.

#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 53;    

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

  Serial.print("\nInitializing 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(53, OUTPUT);     // 10 change this to 53 on a mega
  

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {    Serial.println("initialization failed. Things to check:");
...
etc

I tryed with another MEGA card,... with another SD card (64Mo and 32Go Fat formated by Windows 7)
I can see on oscilloscope the MOSI signal from the MEGA to the SD and the answer (I think) from SD to MEGA on MISO (see attached pictures) when CS is at low state. SCK seems to be correct too.

The connection is as follows:
MEGA pin 50 -> miso (Master in) Card Reader "LC studio"
MEGA pin 51 -> mosi (Master Out)
MEGA pin 52 -> sck (Serial Clock)
MEGA pin 53 -> CS (Chip Select)

In Final ... the perennial failure message above recalled.

I did a voltage matching on the outputs of the player to the MEGA (see diagram image)

Seeking an electrical problem on the SD card reader, I found that the ground pin of the regulator AMS1117 was not connected to the ground of the reader, then I fixed the error and voltages are stable and nominal. I found 52Ko and not 0 Ohms between the Voltage controler's ground and the reader's card ground, measured by Fluke 185. This is a problem, sometimes on this type of player because I found a post on this, once I had identified the problem and the components in question, providing the necessary keywords to search on the net... Chinese electronics... ( Arduino Forum )

I'm interested in any new info, result of experience or constructive idea and thank you in advance.

Cordially.

Great news for me... I did not become sénileet !!

I tryed with an Arduino Uno. The firts tests let me think that I could have to retire early ... but finaly I removed again the 64MB SD card to try an 32GB in FAT32 formatted. Result :

Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card


Besides the first electronic bug, I wonder if :
1) the MEGA coupled to an SD card can be a problem for SD.h
2) a 64MB SD card can be a problem for SD.h
3) a 10 years old Card wich is working fine (I test regularly every hour) can cause problems for SD.h
4) Contrary to what you may read on the official site, the FAT16 could pose a problem SD.h


_ _ _ _ _ /_ _ _ _ _ /_ _ _ _ _ /_ _ _ _ _ Subsequently , why SD.h can't find the FAT? _ _ _ _ _ /_ _ _ _ _ /_ _ _ _ _ /

My 4GB card works fine in my ethernet shield sd slot on a Mega, and I am using the SD library. So I think it is neither the Mega nor the library.

Are there any files that violate the 8.3 filename format on the sd?
The SD library finds mine ok

Is the 64 MB card an MMC card? Also some old cards don't comply with the SD spec.

SD.h only supports SD cards that comply with the SD standard. Macs and Windows machines support old cards but SD.h does not since this would increase the size of the library and few people use cards produced before the standard was finalized.

Also the SD standard requires 64MB cards to be formatted FAT12. SD.h does not support FAT12 file systems.

How did you format the cards? If you used Mac or PC utilities, the card may be formatted with a GUID partition table instead of MBR. PCs and Macs accept GUID partition tables but SD.h does not.

The SD standard requires a MBR partition table. The best way to format SD cards is to use SdFormatter https://www.sdcard.org/downloads/formatter_3/.

It would be helpful if you downloaded SdFat Google Code Archive - Long-term storage for Google Code Project Hosting. and ran the QuickStart and SdInfo examples and posted any error codes from these programs. These programs are in the SdFat/examples folder.

You can also force the 64 MB card to be formatted FAT16 by using the SdFormatter example in the SdFat/examples folder.

Thank you for answer to me SurferTim,

There is just one file in 8.3 format name.
As I wrote, I change the MEGA to be sure that the problem can't be imputed to it.

I think that it will be funny to write an answer
to the scrolling question in your scrolling texte


Thanks too for your answer Fat16Lib,

The 64MB sd card is marked "Multimedia card", so... I think its an MMC...
Thank you for all these tips.

I formatted the cards with SDFormater V3.1. I'll try SdFat and post the results.

it is certain that writing a library as SD.h is a big job. Successful work indeed! Admittedly, this is a big library for a card Uno but perhaps it could be made more efficient for the more powerful cards, such as MEGA and those that will probably come out in the coming months or years...

Are you the author of this library? I think I read somewhere your username !...

anyway, thank you very much

I tryed it, Fat16Lib,

here is the result :

SdFat version: 20120719
type any character to start
card.init failed
SD errorCode: 0X8
SD errorData: 0X1
type any character to start

The card is not an SD card. It must be a MMC (MultiMediaCard) since the error code is 0X8.

SD I/O can be a bit faster with a Mega but not much. AVR SPI is not very efficient.

I have developed a version for Cortex M processors and will release it for the Arduino Due and Teensy 3.0. It runs much faster than the AVR version.

I will provide an option in the AVR library to speedup the Mega a little. Very few people use the Mega and most people use Print to write text files which is very slow. Most people use the Uno and memory is precious with this board.

I have released examples that allow writing binary data much faster. See AnalogIsrLogger20120810.zip http://code.google.com/p/beta-lib/downloads/list. This example logs binary data from an analog pin at up to 100 ksps. It uses a special API to create contiguous files and stream data using multi-block SD write commands.

I don't know if its an MMC, Fat16Lib...

see picture...

have a good day

Scan TLC 503.jpg

This card is a SDHC card so it should work with both SdFat and SD.h libraries.

The card fails on CMD58 which checks whether the card is a standard capacity card or high capacity card and returns the Vdd range supported by the card.

The card returns a status that it is not in a ready state. This means power on initialization has not completed correctly.

CMD58 is only used in SPI mode. A different set of commands is used by a PC or Mac in SDIO mode. This card may work in a PC or Mac but fail in SPI mode.

Does it always return error code 0X8 with error data 0X1?

MMC cards also fail on CMD58 but your card is clearly an SDHC card. MMC cards often fail with error code 0X8 and error data 0X5.

I am going to buy another SD card... 2GB. Appoint it (nominate) SDb, want you ?
I formated it as you told me with SDFormatter.

the result with SDInfo is :

SdFat version: 20120719

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X57

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X57

type any character to start

init time: 47 ms

Card type: SD2
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X4F

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X57

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0XAB

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0XAB

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X55

type any character to start

init time: 39 ms

Card type: SD1
readCID failed
SD errorCode: 0XF
SD errorData: 0X0

type any character to start

It's not the same result for each tests.

For the 32GB of yesterday,... Appoint it SDa,... I have some different results too :

SdFat version: 20120719

type any character to start

card.init failed
SD errorCode: 0X8
SD errorData: 0X1

type any character to start

card.init failed
SD errorCode: 0X8
SD errorData: 0X7F

type any character to start

init time: 47 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 47 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 4 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 75 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

card.init failed
SD errorCode: 0X8
SD errorData: 0X3

type any character to start

init time: 28 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 30 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 31 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

init time: 30 ms

Card type: SDHC
readCID failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

card.init failed
SD errorCode: 0X2
SD errorData: 0X55

type any character to start

A new card seems like a good idea.

I worry that the problem may be noise on the SPI bus. There are often SPI problems with modules like the LC Studio. Most reliable modules have a 5V to 3.3V level shifter based on a buffer chip. Level shifters based on resistors and diodes work poorly with some cards.

Some cards use edge detectors and the sharp signals of a buffer chip work better.

If you new card does not fix the problem, make sure the SPI wires are as short as possible.

That's exactly what I was telling myself :slight_smile:
It's only the difference... the voltage adaptation. If you saw the electronic diagram I made based on the LC studio card reader (black components) and my adaptation système, you can see three diodes... I recommend Schottky diodes like BAT85 and now I just have some 1N4148... then the high level is 3.3V but the low one is 0,6V. it is certainly not ideal. I'll work with (on) that now.

thank you very much for your advice
Have a good evening, although it is perhaps a little early for you at this time...
Best regards

:slight_smile:

With SDb & UNO :

SdFat version: 20120719

type any character to start

init time: 3 ms

Card type: SD2

Manufacturer ID: 0X6F
OEM ID:
Product: SMI
Version: 1.0
Serial number: 0
Manufacturing date: 7/2012

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

SD Partition Table
part,boot,type,start,length
1,0X0,0X6,131,3886973
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT16
blocksPerCluster: 64
clusterCount: 60726
freeClusters: 60725
fatStartBlock: 132
fatCount: 2
blocksPerFat: 238
rootDirStart: 608
dataStartBlock: 640

type any character to start

With SDa & UNO :

SdFat version: 20120719

type any character to start

init time: 2 ms

Card type: SDHC

Manufacturer ID: 0X1B
OEM ID: SM
Product: 00000
Version: 1.0
Serial number: 2330206577
Manufacturing date: 10/2011

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

SD Partition Table
part,boot,type,start,length
1,0X0,0XC,8192,61295848
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT32
blocksPerCluster: 64
clusterCount: 957491
freeClusters: 957490
fatStartBlock: 9614
fatCount: 2
blocksPerFat: 7481
rootDirStart: 2
dataStartBlock: 24576

type any character to start

Tomorrow, I'll try with the MEGA

Is it bad luck ?

First test:
64 MB SD card, 10 years old.
Arduino MEGA under SD.h & CardInfo.
SD card reader (LC studio) on witch one the ground pin of the tension controler 3.3V AMS1117 was not connected to the card ground.
Result : Negative.

Second test :
Same cards but bug repaired (see pictures above)
Result : Negative.

Third test :
Exchange SD card for 32GB
Same cards.
Result : Negative.

Fourth test :
Same cards but with level adaptation 5V MEGA / 3,3V SD card
(See Levels Adaptation Diagram above)(with 1N4148 instead of BAT83 I advocate).
Result : Negative.

Fifth test :
Exchange SD card for 64MB 10yo
UNO card...
Resultat : Negative.

Sixth test :
UNO under SDFatLib & SDInfo.
Result : Negative.

Seventh test :
Exchange SD card for 32GB
Result : half positive(reporting error codes by the program).

Eighth test :
Exchange SD card for a new 2GB.
Result : half positive(reporting error codes by the program).

Ninth test :
exchange 1N4148 (See Levels Adaptation Diagram above) for some BAT83.
Result : Positive

Tenth test :
Exchange SD card for 32GB.
Result : Positive

Eleventh test :
Exchange SD card for 64MB.
Result : Negative.

Twelfth test :
Uno under SD.h & CardInfo.
Result : Positive

Thirteenth test :
MEGA under SD.h & CardInfo OR under SDFatLib & SDInfo.
Result : Positive

Conclusions :

  • SD cards that was existing before the SD standard completion are not preferred.
  • The cards are sensitive to the shape of the signals.
  • Some "LC studio" card readers have a mass default.

Thank you very much, Fat16Lib and Jean-François for your help. :slight_smile:

LibertyCareche:

  • Some "LC studio" card readers have a mass default.

Looking at this image and also at the related thread in the French section of the forum, a better English translation of « Certains lecteurs de carte "LC studio" ont un défaut masse » would be “Some "LC studio" card readers have a ground fault”.

!!! ..??

Yes, your right... I passed my time to work on electronics and not translation... it becomes like that... sorry !?
It would be more positive for you to write this ... in French... no ?
There are people who collect posts by this way,... there is others who work... it's the life.
But... thx

I had the same problem with the MEGA and I was able to change the pins within the code and it worked properly. thank you for the help.

below is the code I used and I modified it/made notes for some more people can understand.

/*
SD card test - It checks to see if the wiring is correct, card is inserted and compatible ( Used: LC STUDIO SD CARD READER )

This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.

The circuit:

  • SD card attached to SPI bus as follows:
    ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
    ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
    ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
    ** CS - depends on your SD card shield or module.
    Pin 4 used here for consistency with other Arduino examples

created 28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
modified 17 July 2015
by Nandi Sevillian
*/

// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8

/*FOR MEGA PLACE THESE PINS FOR THIS TO WORK

  • NOTE THAT I DONT HAVE A SHIELD just the LC STUDIO SD CARD READER AND ARDUINO MEGA
  • MEGA pin 50 -> miso (Master in) Card Reader "LC studio"
  • MEGA pin 51 -> mosi (Master Out)
  • MEGA pin 52 -> sck (Serial Clock)
  • MEGA pin 53 -> CS (Chip Select)
  • I have a SanDisk 8GB SDHC Card inserted inside and it works properly.
    */
    const int chipSelect = 53;

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...");

// 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 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) {

}

/***********************************************************************************************************************************************************/

/*
when the Serial monitor is open then this is my print statement

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

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3644850176
Volume size (Kbytes): 3559424
Volume size (Mbytes): 3476

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