Pages: [1]   Go Down
Author Topic: SD library mod for SPI_QUARTER_SPEED  (Read 1390 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
with
Code:
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint8_t spiSpeed = SPI_HALF_SPEED);

and in SD.cpp file,replace
Code:
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:
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:
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.
« Last Edit: May 30, 2012, 06:02:34 pm by mcash » Logged

Pages: [1]   Go Up
Jump to: