Go Down

Topic: Two SD card / 1 arduino (Read 1 time) previous topic - next topic

kev1

Hello,

I would like to use with Arduino Mega the sd slot on the ethernet shield to log events, and another sd shield to log differents datas. Both shields work fine separately, but I can't use them together.
So, first I would like to know if it's possible... I think yes because they use SPI bus and two differents CS pin. But how manipulate the SD library? I tried to create two instances of SD library and it doesn't seem to work.

Thanks

PaulS

Quote
I tried to create two instances of SD library

How? The SD class has a constructor, but you never (need to) call it. There is an instance of the class created in the header file.

You need to make a number of changes to the class to support multiple instances.

kev1

#2
Jul 09, 2013, 04:19 pm Last Edit: Jul 10, 2013, 09:30 am by kev1 Reason: 1
I finally downloaded the library from https://github.com/adafruit/SD.
Indeed, you have to make changes to the class to support multiple instances, but just one at the line 453 in SD.cpp.
I replaced
Code: [Select]
if ( ! file.open(SD.root, filepath, mode)) by
Code: [Select]
if ( ! file.open(root, filepath, mode))
I don't understand why the SD object is used in the class...
It seems to works fine now.



fat16lib

The Adafruit SD.h and the standard SD.h are based on a version of SdFat that does not support multiple cards.

Newer versions of SdFat http://code.google.com/p/sdfatlib/downloads/list can support multiple SD cards.

You just need to edit SdFatConfig.h and change this line.  Set USE_MULTIPLE_CARDS nonzero:
Code: [Select]

/**
* To use multiple SD cards set USE_MULTIPLE_CARDS nonzero.
*
* Using multiple cards costs about 200  bytes of flash.
*
* Each card requires about 550 bytes of SRAM so use of a Mega is recommended.
*/
#define USE_MULTIPLE_CARDS 0


See TwoCards.ino in the examples folder for how to use two SdFat objects.

kev1

Ok thanks for your help, I will try that.

kev1

I'm trying to use the new version of SdFat as fat16lib suggested to me but I got the following error:
Code: [Select]
undefined reference to 'vtable for SdFile'
I'm using Codeblocks Arduino IDE and I added the SdFat folder to the librairies.
I don't know how to solve this problem... Any ideas?

fat16lib

This is a long shot.  I understand Code::blocks may give that error for an undefined virtual destructor.

Try editing SdFatConfig.h and set DESTRUCTOR_CLOSES_FILE non-zero like this
Code: [Select]

/**
* Set DESTRUCTOR_CLOSES_FILE nonzero to close a file in its destructor.
*
* Causes use of lots of heap in ARM.
*/
#define DESTRUCTOR_CLOSES_FILE 1

kev1

I tried to set DESTRUCTOR_CLOSES_FILE nonzero but i still got the error.
Is the error related to Code::blocks ?

fat16lib

Quote

Is the error related to Code::blocks ?


Yes, the multiple SD card option works with the Arduino IDE.

A number of software packages have this problem with Code::Blocks.  Just google for this:

code:blocks "undefined reference to vtable"

I don't test SdFat with Code:Blocks so I can't help.

kev1

Ok, indeed I tried to compile on the Arduino IDE and it works fine.
But I noticed that I have to explicitly include the SdFat library in the ino file (and not through a header file). So I tried to do the same with Code:Blocks, and it works fine... (except for some warnings).
I don't know why we can't include arduino libraries through a header file ...?

Thanks for help !

Go Up