Go Down

Topic: SD card multiple initialization (Read 2651 times) previous topic - next topic

VittorioLippi

Hi,
I'm working on a project in which i'm using the arduino (mega2560) to read pictures from an sd card and display them on different oled motitors. Both the sd card and the oled screens are communuicating through the same SPI port. I'm reading the an SD card from the ethernet shield.
Originally, when i reading a pic from the SD card, i used SD.begin in the typical way: 
Code: [Select]
 
if (!SD.begin(4)) {
      return;
      }


where 'return' was intended to abruptly stop the image reading funcion.
My problem is that, SD.begin(4) always returns zero after the first call and hence i'm able to visualize only an image.
i tried to use SD.begin into an initialization function (i.e. only once at the beginning of the program) and it was not working.

Now i took away the 'return' command and it is working properly, but i would like to do something better than going blindy into the procedure.
For example i would like to be able to discriminate, at run-time, between a failure into the SD card initialization and later problems such as 'file not found'

Probably there is something i have misunderstood about the little sweet 'SD.begin()' function

thanks in advance for any suggestion.

fat16lib

Normally you only need to call SD.begin() once in setup().

If you change SD cards, SD.begin() must be called before the new card can be used.

The begin() function has a problem with multiple calls.  See this:

http://arduino.cc/forum/index.php/topic,66415.0.html

SD.h is a wrapper for an old version of the SdFat library.  This older version of SdFat does not coexist as well with other SPI devices as newer versions of SdFat.

You may want to use the newest version of SdFat without the SD.h wrapper.  SdFat is here:

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

VittorioLippi


SD.h is a wrapper for an old version of the SdFat library.  This older version of SdFat does not coexist as well with other SPI devices as newer versions of SdFat.
You may want to use the newest version of SdFat without the SD.h wrapper.  SdFat is here:
http://code.google.com/p/sdfatlib/


Thank you very much for thew quick reply - i'll check the difference and i'll report it here ASAP

V.

Go Up