Skip to content

Commit 3460b7d

Browse files
committed
Add option to set SPI frequency in SD.begin(...)
1 parent ae147c8 commit 3460b7d

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/SD.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ boolean SDClass::begin(uint8_t csPin) {
347347
root.openRoot(volume);
348348
}
349349

350-
350+
boolean SDClass::begin(uint32_t clock, uint8_t csPin) {
351+
return card.init(SPI_HALF_SPEED, csPin) &&
352+
card.setSpiClock(clock) &&
353+
volume.init(card) &&
354+
root.openRoot(volume);
355+
}
351356

352357
// this little helper is used to traverse paths
353358
SdFile SDClass::getParentDir(const char *filepath, int *index) {

src/SD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SDClass {
6868
// This needs to be called to set up the connection to the SD card
6969
// before other methods are used.
7070
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
71+
boolean begin(uint32_t clock, uint8_t csPin);
7172

7273
// Open the specified file/directory with the supplied mode (e.g. read or
7374
// write, etc). Returns a File object for interacting with the file.

src/utility/Sd2Card.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,15 @@ uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
540540
#endif // USE_SPI_LIB
541541
return true;
542542
}
543+
#ifdef USE_SPI_LIB
544+
//------------------------------------------------------------------------------
545+
// set the SPI clock frequency
546+
uint8_t Sd2Card::setSpiClock(uint32_t clock)
547+
{
548+
settings = SPISettings(clock, MSBFIRST, SPI_MODE0);
549+
return true;
550+
}
551+
#endif
543552
//------------------------------------------------------------------------------
544553
// wait for card to go not busy
545554
uint8_t Sd2Card::waitNotBusy(uint16_t timeoutMillis) {

src/utility/Sd2Card.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class Sd2Card {
223223
}
224224
void readEnd(void);
225225
uint8_t setSckRate(uint8_t sckRateID);
226+
#ifdef USE_SPI_LIB
227+
uint8_t setSpiClock(uint32_t clock);
228+
#endif
226229
/** Return the card type: SD V1, SD V2 or SDHC */
227230
uint8_t type(void) const {return type_;}
228231
uint8_t writeBlock(uint32_t blockNumber, const uint8_t* src);

0 commit comments

Comments
 (0)