Go Down

Topic: New IDE 1.8.0, SD card library doesn't work, but it used to in 1.6.7 (Read 1 time) previous topic - next topic

SouthernAtHeart

When I run the example sketch in 1.6.7 for the SD library called 'list files', it works, and lists the files on my SD card.  When I updated to 1.8.0, that example file does not work, but gives me the error, cards initialization failure.
???

SouthernAtHeart

My Card is formatted as Fat32.  Does that not work with the 1.8.0 SD Library? I can't format it as Fat16, because it's 8Gb, and I think it has to be 2Gb or smaller for Fat16

SouthernAtHeart

Still no luck running the example sketch for SD card library in the latest 1.8.0   This version doesn't look like it's just a beta version, or is it? Below is the example sketch.  If I run 1.6.7, and open this example sketch, it works.  But it doesn't work on 1.8.0.  The init of the card fails.
Code: [Select]
/*
  Listfiles

 This example shows how print out the files in a
 directory on a SD card

 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 2 Feb 2014
 by Scott Fitzgerald

 This example code is in the public domain.

 */
#include <SPI.h>
#include <SD.h>

File root;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  root = SD.open("/");

  printDirectory(root, 0);

  Serial.println("done!");
}

void loop() {
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}



Aamir_Nadeem

SD card read/write fails in IDE 1.8.0 using Arduino Uno and Ethernet Shield. Reports that SD card is found and initialized properly but fails to read or write on it. But if card is formatted FAT32 then initialization also fails.
Problem can be sollved by uninstalling IDE 1.8.0 and reinstalling older IDE 1.6.8.

Terryjmyers

bump, this is still an issue.  However I've confirmed that the last version my script works in in 1.6.9.  All later versions (I tested them all) it does not work in.  All 1.6.X versions it reports that it works, but no data can be retrieved.  1.8.0 it does not report that it works at all.

I tried pasting my code but it exceeded the 9000 character limit. 
https://github.com/terryjmyers

nsx1

I wanted to chime in and state that I, too, am having difficulty with version 1.8.0 while attempting SD file access and directory listing.  I can attest that up to version 1.6.12 all was working fine with my Arduino Zero; however, now with 1.8.0 it fails consistently.  Nothing has changed in my code so it is quite odd.

Other pertinent information, the core utilized is 1.6.11 and it works fine w/ the 1.6.12 IDE and seems to upload fine with 1.8.0.  All other SPI actions work fine, just the SD component fails.  I'm really at a loss as to what to do for the code works fine when compiled in prior versions of IDE.

Any thoughts?


Code: [Select]

#include <SPI.h>
#include <SD.h>

 pinMode(10, OUTPUT); // change this to 53 on a mega

  if( !SD.begin( SD_CS )) {
    // failed
   // card that is NOT inserted.
    print( sderror );
    return;
  }


File dir = SD.open( "/" );
  dir.seek(0);

  while( true ) {
    File entry = dir.openNextFile();
    if( !entry ) {
      entry.close();
      break;
    }

    // header
    print( (const uint8_t *)entry.name() );
    if( entry.isDirectory() ) {
      print( slashmsg );
    }

    if( entry.isDirectory() ) {
      // directory ending
      for( int i=strlen( entry.name()) ; i<16 ; i++ ) {
        print( space );
      }
      print( dirextmsg );
    }
    else {
      // file ending
       print( CR_LF );
    }
    line_terminator();
    entry.close();
  }
  dir.close();

abpimport

Same issue here, sketch running fine with 1.6.X starts to fail with 1.8.0...

Try to debug a little bit and the issue seems to come from root.openRoot(volume) in SD.begin()...

Federico Vanzati

Hi all,

I must say thanks to @abmimport for making me notice this thread!

We started investigating after receiving some reports like yours and we were able to replicate the issue and narrow down to the origin of the problem.
The issue is related to some improvements we brought to the SD library in order to increase its performances. The fact is that only certain SD card are not working with the 1.1.0 SD library (for example I have a 4GB-Class4 and a Sandisk-Ultra-8GB-Class10 that are working and a Verbatim-8GB-Class4 that is not working) and we need some data in order to fix this.

So can I ask you to provide some information about the micro SD card are you using, such as: brand, model, capacity and class.
Also the shield or the Adapter you are using.

There's also a github issue so if you gently want to post your feedback there will help us a lot to track down the issue:
https://github.com/arduino/Arduino/issues/5792


In the meanwhile you should be able to use your SD card with the 1.8.0 Arduino IDE by simply installing the SD library 1.0.9 from the Library manager

Thank you for the contribution
Federico
F

rpt007

Had similar problems with IDE 1.8 and IDE 1.6.13 on my Mac today.
All my SD cards were not recognized.
I had already formatted all cards with the special SDFormatter, but no card was detected.

As recommended the downgrade of IDE 1.8 from SD library 1.10 to SD library 1.09 -> no change. Still my cards were not recognized (initialization failure).
Did the tests with a standalone SD card module (clone of Adafruit's latest model) and a Nano as MCU, then with an UNO and an Ethernet shield with SD card on board -> no success.

Then I re-formatted one of my cards with the SDFormatter again, this time checking the "interoperability" option:

This eventually did the trick (at least for me) and my card showed up with all details using the SDCard Info sketch. Whow - 2 hours sweat and now a big relief (for the time being, let's see what happens tomorrow). Repeated the re-formatting with the remaining cards - all of them are now accepted by my SD card module!

As requested some information about the cards:
- 1GB SD (old card, unknown manufacturer and no further details available - but working!!)
- 4GB HC Class 4 / Kingston
- 8GB HC Class 6 / Platinum
Before you ask:
Did you really read and understand "How to use this forum"  -> http://forum.arduino.cc/index.php?topic=148996.0
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)


fat16lib

The problem may be this mod in Sd2Card.cpp.


Loops like this:
Code: [Select]

  for (uint16_t i = 0; i < count; i++) {
    dst[i] = spiRec();
  }


Were replace by this:
Code: [Select]
spiRec(dst, count);

SpiRec() is this new function:
Code: [Select]

void spiRec(uint8_t* data, int size) {
#ifdef USE_SPI_LIB
  SDCARD_SPI.transfer(data, size);
#else
  while (size) {
    *data++ = spiRec();
    size--;
  }
#endif
}


USE_SPI_LIB is defined so transfer(data, size) is used.

The problem may be that transfer(data, size) sends the content of the 'data' buffer to the card and stores received bytes in the 'data' buffer.

Some SD cards may interpret the data sent over MOSI as a command.  Commands start with a byte that has bit-7 low and bit-6 high.  the command index is bits 0-5.

My original version sent all 0XFF bytes on MOSI to avoid this possibility.

I you are having a problem try replacing the call to  spiRec() with the original loop.

the file is located here:

arduino-1.8.0/libraries/SD/src/utility/Sd2Card.cpp.

You could just edit spiRec like this:
Code: [Select]

void spiRec(uint8_t* data, int size) {
#ifdef USE_SPI_LIB
  for (int i = 0; i < size; i++) {
    data[i] = SDCARD_SPI.transfer(0XFF);
  }
#else
  while (size) {
    *data++ = spiRec();
    size--;
  }
#endif
}



fat16lib

If anyone from Arduino reads this please consider a new version of SPI.transfer().

Many RTOS HAL libraries have a transfer function with three arguments.

Code: [Select]
void spiExchange(size_t n, const void* txbuf, void* rxbuf);

It's like the current transfer if both txbuf and rxbuf are non-null.

If txbuf is null, 0XFF bytes are sent.  If rxbuf is null, receive data is discarded.

This allows every possible option, send from one buffer and receive to another buffer,  exchange data in a single buffer, send with no receive buffer, and receive with no send buffer.

fat16lib

I found a 16GB Samsung card that fails with the 1.80 Datalogger example.

I modified spiRec() like this:
Code: [Select]

void spiRec(uint8_t* data, int size) {
#ifdef USE_SPI_LIB
#define FIX 1
#if FIX
  for (int i = 0; i < size; i++) {
    data[i] = SDCARD_SPI.transfer(0XFF);
  }
#else
  SDCARD_SPI.transfer(data, size);
#endif
#else
  while (size) {
    *data++ = spiRec();
    size--;
  }
#endif
}


When FIX is defined to be one, it works

Code: [Select]

Initializing SD card...card initialized.
433,350,296
350,342,317
331,335,324
316,318,316


and when FIX is defined to be zero it fails
Code: [Select]

Initializing SD card...Card failed, or not present
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy