Go Down

Topic: SD library mod for SPI_QUARTER_SPEED (Read 8748 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.

StanCh

I have a problem with a SD micro module with LS 125 chip on a PCB board. I use Arduino IDE version 1.8 with a SD library by a Sparkfun dated at 2010 inside a code. I found a solution here as to write SPI_QUARTER_SPEED into card init for example:
   SD.begin()
   if (!card.init(SPI_QUARTER_SPEED, chipSelect))
I am not shure that this works and a library was updated because I cannot find such a keyword inside a SD.h. Can anyone tell me how to test this to be shure that it works?
Or maybe I ought to make a correction to a SD code ezplained above?
Arduino Mega256,Nano,Pro Mini
It's very hard to start with.

knut_ny

the post U read was 5 yrs old.  Libraries are updated.  New documentation can be found
Ny

Go Up