Arduino M0 multiple SD card module problem

Hello i did mange to get the SD card module working. But my Goal was to have a Second Sd card module for Data Logging. One Sd card for one Sensor and the Second Sd card for a second Sensor. So i used the Example Sd card sketch Filelist. Just to see if i can see both Sd card modules. Both have different Select pin one on D4 and one on D5.

So i powered up the modules and sense D4 was by default in there it saw a demo information i put in there. But when i change in the sketch to D5 it said Failed t read card.

So the next thing i did i turn off the power the first Sd card and just left the Second Sd card module and reset the arduino and it was able to see the the demo information on the Second Sd card module. So I'm not sure what is the problem. Can someone please help me out?

It looks like a Bug of some kind in the Spi of the Arduino library maybe?

SD.h only supports one card. I wrote the version of SdFat used in SD.h over six years ago when only 328 AVR Arduinos existed.

Modern versions of SdFat support multiple cards. Each card requires about 600 bytes of RAM for a card cache and file system objects.

See the SdFat TwoCard example.

Hello fat16lib i will give it try thank you. I will post a update on what happens.

Here is my update.

I uploaded the sketch it said i was missing the Sdfat library so i downloaded it from the same owner. and installed it. Then i reopen the Arduino IDE and ran the Sketch. Sense the M0 then open the Serial monitor. Then i hit the restart button and it displayed this

FreeStack: 28044
type any character to start

So i typed in some characters hit enter and nothing happen. That is about it. then i disconnected the power usb from the arduino and pulled the Sd cards and put them into my pc and first SD i open has a Folder called Dir1 Second Sd card has nothing in it. Now I'm back here.

Try running the QuickStart example. I assume you still are using pins 4 and 5 for chip select.

First set the DISABLE_CHIP_SELECT symbol to 4 and enter 5 at the prompt.

Next set DISABLE_CHIP_SELECT to 5 and enter 4 at the prompt.

You should see something like this for each card. I ran it on a Uno.

SPI pins:
MISO: 12
MOSI: 11
SCK: 13
SS: 10

SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10

Enter the chip select pin number: 5

Disabling SPI device on pin 4

Card successfully initialized.

Card size: 16004 MB (MB = 1,000,000 bytes)

Volume is FAT32, Cluster size (bytes): 32768

Files found (date time size name):
2000-01-01 01:00:00 22624 adc4pin00.csv
2000-01-01 01:00:00 128890 bench0.txt

Success! Type any character to restart.

If QuickStart works with both cards try the TwoCards example with SD1_CS set to 4 and SD2_CS set to 5.

If that fails try reversing the order, set SD1_CS to 5 and SD2_CS to 4.

If both fail, try finding the point of failure by inserting print statements.

The TwoCard example should print something like this. Again, I ran it on an Uno.

FreeStack: 333
type any character to start
------sd1 root-------
Dir1/
------sd2 root-------
Dir2/
------sd1 Dir1-------
------sd2 Dir2-------

Writing test.bin to sd1
Copying test.bin to copy.bin
File size: 1000000
Copy time: 6288 millis
------sd1 -------
2000-01-01 01:00:00 0 Dir1/
2000-01-01 01:00:00 1000000 test.bin
------sd2 -------
2000-01-01 01:00:00 0 Dir2/
2000-01-01 01:00:00 1000000 copy.bin

Renaming copy.bin
------sd1 -------
2000-01-01 01:00:00 0 Dir1/
2000-01-01 01:00:00 1000000 test.bin
------sd2 -------
2000-01-01 01:00:00 0 Dir2/
2000-01-01 01:00:00 1000000 rename.bin

Done

You can try one more thing. When I run TwoCard on a Due, it fails unless I slow the SPI clock. Sometime multiple SPI module load the SPI bus.

Try changing the begin calls like this.

  // initialize the first card
  if (!sd1.begin(SD1_CS, SD_SCK_MHZ(4))) {
    sd1.initError("sd1:");
  }


...


  // initialize the second card
  if (!sd2.begin(SD2_CS, SD_SCK_MHZ(4))) {
    sd2.initError("sd2:");
  }

Okay in card one this is what i got from the Quickstart

i put const int8_t DISABLE_CHIP_SELECT = 4; and typed 5 in the serial monitor and i got this

5

Disabling SPI device on pin 4

when i put in const int8_t DISABLE_CHIP_SELECT = 5; and typed in 4 in the serial monitor i get

4

Disabling SPI device on pin 5

Card successfully initialized.

Card size: 7839 MB (MB = 1,000,000 bytes)

Volume is FAT32, Cluster size (bytes): 32768

Files found (date time size name):
2000-01-01 01:00:00 0 Dir1/

Success! Type any character to restart.

Look like a hardware problem. You may have SD modules that can't share the SPI bus.

There have been flood of these on ebay and other low cost sellers. Can you provide a link to a web page for the modules.

The other mystery is why the failure message is not printed.

Here is the link to where i got mine from. Ebay page

Looks like you have the modules with the sharing problem. These are usually a clone of the Catalex MicroSD Card Adapter.

If you search the forum you will find various post about the problem. They work fine if you have one and it is the only device on the SPI bus.

That is what i was afraid of that. Is there anything i can do. I don't honestly have the money to buy something else I'm on a fix budget?

It's a fundamental electronics problem and the board is almost impossible to modify for the average user.

I use this module with 3.3V ARM boards. It has no level shifter so can't be used with 5V AVR Arduinos even though the ebay sellers claim its OK for AVR.

I don't mind using everything at 3.3v even the logic i can deal with that. I will look into it thank you.

The fix is pretty simple electrically - you need a buffer on the MISO line coming from both boards to ensure the card is not hogging the MISO line and interfering with the other. In a 5V system, I use one gate of a 74HC125 with its OE/ line connected to the CS for that board. With 3.3V, you may need a slightly different chip.

You also need enough 3.3V current to have both boards/cards powered at one time, as one can be doing background stuff while the other is talking over the SPI bus.

I might be off crossroads but it sounded like a shift register Right. Let one go first then move on to the second one.

I'm able to write to both Sd card using the sample Sd card write.

this is what i did to wire them to work. I'm not using the Sd card modules i directly wired the sd card adapter with male header pins. I know it's not the correctly way to do but i wanted to try it. I did mange to search online on this topic and found the Sd card modules as Fat16lib said there is a problem with these module chips So i searched online how i can wire directly the Sd card adapter with the arduino and found This

Initializing SD card...initialization done.
Writing to test.txt...done.
test.txt:
testing 1, 2, 3.
testing 1, 2, 3.
testing 1, 2, 3.

Initializing SD card...initialization done.
Writing to test2.txt...done.
test2.txt:
testing2 1, 2, 3.
testing2 1, 2, 3.
testing2 1, 2, 3.

I tried the twocard sketch again to see and this is what i got.

FreeStack: 28044
type any character to start
------sd1 root-------
Dir1/
------sd2 root-------
Dir2/
------sd1 Dir1-------
------sd2 Dir2-------

Writing test.bin to sd1

You might want to try this Catalex Fix.

I went into the Sd cards and all files and folders are there in both Sd cards. so it looks like it is working.