瀏覽代碼

Fix ESP8266 SPI divisor calculation

main
Bill Greiman 8 年之前
父節點
當前提交
6ac05353a6
共有 2 個文件被更改,包括 6 次插入6 次删除
  1. +2
    -3
      SdFat/src/SdSpiCard/SdSpi.h
  2. +4
    -3
      SdFat/src/SdSpiCard/SdSpiESP8266.cpp

+ 2
- 3
SdFat/src/SdSpiCard/SdSpi.h 查看文件

@@ -156,11 +156,11 @@ class SdSpiLib {
*/
void beginTransaction(uint8_t divisor) {
#if ENABLE_SPI_TRANSACTIONS
SPISettings settings(F_CPU/(divisor ? divisor : 1), MSBFIRST, SPI_MODE0);
SPI.beginTransaction(settings);
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
#else // ENABLE_SPI_TRANSACTIONS
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#endif // ENABLE_SPI_TRANSACTIONS
#ifndef SPI_CLOCK_DIV128
SPI.setClockDivider(divisor);
#else // SPI_CLOCK_DIV128
@@ -182,7 +182,6 @@ class SdSpiLib {
}
SPI.setClockDivider(v);
#endif // SPI_CLOCK_DIV128
#endif // ENABLE_SPI_TRANSACTIONS
}
/**
* End SPI transaction.

+ 4
- 3
SdFat/src/SdSpiCard/SdSpiESP8266.cpp 查看文件

@@ -34,16 +34,17 @@ void SdSpi::begin(uint8_t chipSelectPin) {
//------------------------------------------------------------------------------
/** Set SPI options for access to SD/SDHC cards.
*
* \param[in] divisor SCK clock divider relative to the system clock.
* \param[in] divisor SCK clock divider relative to the max SPI clock.
*/
void SdSpi::beginTransaction(uint8_t divisor) {
const uint32_t F_SPI_MAX = 80000000;
#if ENABLE_SPI_TRANSACTIONS
// Note: ESP8266 beginTransaction does not protect for interrupts.
SPISettings settings(F_CPU/(divisor ? divisor : 1), MSBFIRST, SPI_MODE0);
SPISettings settings(F_SPI_MAX/(divisor ? divisor : 1), MSBFIRST, SPI_MODE0);
SPI.beginTransaction(settings);
#else // ENABLE_SPI_TRANSACTIONS
// Note: ESP8266 beginTransaction is the same as following code.
SPI.setFrequency(F_CPU/(divisor ? divisor : 1));
SPI.setFrequency(F_SPI_MAX/(divisor ? divisor : 1));
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#endif // ENABLE_SPI_TRANSACTIONS

Loading…
取消
儲存