Pages: [1]   Go Down
Author Topic: Two SD card / 1 arduino  (Read 1271 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50923
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if ( ! file.open(SD.root, filepath, mode))
by
Code:
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.


« Last Edit: July 10, 2013, 02:30:18 am by kev1 » Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/**
 * 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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok thanks for your help, I will try that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to use the new version of SdFat as fat16lib suggested to me but I got the following error:
Code:
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?
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/**
 * 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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !
Logged

Pages: [1]   Go Up
Jump to: