Go Down

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

jl-p

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!");
 }
 else
   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?");
   return;
 } 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:
     Serial.println("SD1");
     break;
   case SD_CARD_TYPE_SD2:
     Serial.println("SD2");
     break;
   case SD_CARD_TYPE_SDHC:
     Serial.println("SDHC");
     break;
   default:
     Serial.println("Unknown");
 }

 // 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");
   return;
 }

 // 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);
 Serial.println();

 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.println(volumesize);
 Serial.print("Volume size (Kbytes): ");
 volumesize /= 1024;
 Serial.println(volumesize);
 Serial.print("Volume size (Mbytes): ");
 volumesize /= 1024;
 Serial.println(volumesize);


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

 // 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


johnwasser


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:
http://arduino.cc/en/Reference/SPISetClockDivider
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


jl-p

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

Go Up