Go Down

Topic: SD Card. see the card but not the volume when other spi devices are connected (Read 653 times) previous topic - next topic


I have a Ethernet Shield, And a SPI TFT screen.
When i load the default cardinfo sketch and add the lines for the spi pins for the screen  as shown in the code
I have both connected and the TFT and the Ethernetshield.
when the tft is connected i can see the card but not the volume. can anyone explain it.
when i disconnect the tft the SD card can be read.
the screen is functioning ok even when the ethernet shield is connected.

Code: [Select]

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

#define RA8875_CS_Pin 32
#define RA8875_Reset_Pin 30
#define SD_chipSelect 4
#define Ethernet_chipSelect 10

Sd2Card card;
SdVolume volume;
SdFile root;

void setup()
{  Serial.begin(115200);
  Serial.print("\nInitializing SD card...");

 pinMode(30, OUTPUT);
 pinMode(RA8875_CS_Pin, OUTPUT);
 pinMode(SD_chipSelect, OUTPUT);
 pinMode(Ethernet_chipSelect, OUTPUT);
 SPI.setClockDivider(SD_chipSelect, 21);
 digitalWrite(SD_chipSelect, HIGH);
 SPI.setClockDivider(Ethernet_chipSelect, 84);
 digitalWrite(Ethernet_chipSelect, HIGH);
 SPI.setClockDivider(RA8875_CS_Pin, 1);
 digitalWrite(RA8875_CS_Pin, HIGH);

 if (!SD.begin(SD_chipSelect)) {
   Serial.println("SD initialization failed!");
   Serial.println("SD initialization done.");

// we'll use the initialization code from the utility libraries
 // since we're just testing if the card is working!
 if (!card.init(SPI_HALF_SPEED, SD_chipSelect)) {
   Serial.println("initialization failed. Things to check:");
   Serial.println("* is a card is inserted?");
   Serial.println("* Is your wiring correct?");
   Serial.println("* did you change the chipSelect pin to match your shield or module?");
 } else {
   Serial.println("Wiring is correct and a card is present.");

 // print the type of card
 Serial.print("\nCard type: ");
 switch (card.type()) {
   case SD_CARD_TYPE_SD1:
   case SD_CARD_TYPE_SD2:

 // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
 if (!volume.init(card)) {
   Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");

 // print the type and size of the first FAT-type volume
 uint32_t volumesize;
 Serial.print("\nVolume type is FAT");
 Serial.println(volume.fatType(), DEC);

 volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
 volumesize *= volume.clusterCount();       // we'll have a lot of clusters
 volumesize *= 512;                            // SD card blocks are always 512 bytes
 Serial.print("Volume size (bytes): ");
 Serial.print("Volume size (Kbytes): ");
 volumesize /= 1024;
 Serial.print("Volume size (Mbytes): ");
 volumesize /= 1024;

 Serial.println("\nFiles found on the card (name, date and size in bytes): ");

 // list all files in the card with date and size
 root.ls(LS_R | LS_DATE | LS_SIZE);

void loop(void) {


Code: [Select]

//   When Ethernet shield and TFT are connected.

Initializing SD card...
SD initialization failed!
Wiring is correct and a card is present.

Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

// Only Ethernet Shield connected

Initializing SD card...
SD initialization done.
Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3711934464
Volume size (Kbytes): 3624936
Volume size (Mbytes): 3539

Files found on the card (name, date and size in bytes):
TEST.TXT      2000-01-01 01:00:00 162
TROMMEL.TXT   2000-01-01 01:00:00 55
DATALOG.TXT   2000-01-01 01:00:00 1681947


Code: [Select]

 SPI.setClockDivider(Ethernet_chipSelect, 84);
 SPI.setClockDivider(RA8875_CS_Pin, 1);

That form of the SPI.setClockDivider() only works on the Arduino DUE:
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp



i noticed that the issue only exist with sdhc and not with sd2 cards

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!

via Egeo 16
Torino, 10131