Go Down

Topic: SD library mod for SPI_QUARTER_SPEED (Read 2168 times) previous topic - next topic

mcash

May 31, 2012, 12:01 am Last Edit: May 31, 2012, 01:02 am by mcash Reason: 1
Hello,
I don't know if anyone else faced this problem, but recent I came across an SD card that only works with SPI quarter speed... (had to use the QuickStart example of the SdFat library to figure that out).
I did not notice any method in the SD library to change the SPI speed. It can be achieved by a little modification in the library.

In SD.h file,  replace
Code: [Select]
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
with
Code: [Select]
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint8_t spiSpeed = SPI_HALF_SPEED);

and in SD.cpp file,replace
Code: [Select]
boolean SDClass::begin(uint8_t csPin) {
 /*

   Performs the initialisation required by the sdfatlib library.

   Return true if initialization succeeds, false otherwise.

  */
 return card.init(SPI_HALF_SPEED, csPin) &&
        volume.init(card) &&
        root.openRoot(volume);
}

with
Code: [Select]
boolean SDClass::begin(uint8_t csPin, uint8_t spiSpeed) {
 /*

   Performs the initialisation required by the sdfatlib library.

   Return true if initialization succeeds, false otherwise.

  */
 return card.init(spiSpeed, csPin) &&
        volume.init(card) &&
        root.openRoot(volume);
}


After these modifications any of the following methods can be used to start the SD object.
Code: [Select]
SD.begin();
SD.begin(cspin);
SD.begin(cspin, spiSpeed);


spiSpeed (which is optional) can be SPI_FULL_SPEED, SPI_HALF_SPEED or SPI_QUARTER_SPEED as supported by SD2Card class.

Hope this helps.

Go Up