Skip to content

Commit 61d0b08

Browse files
slowbrothinkyhead
authored andcommitted
🎨 Prefer DELAY_NS over DELAY_CYCLES (#22382)
1 parent b57f73a commit 61d0b08

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Marlin/src/HAL/DUE/HAL_SPI.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
}
241241

242242
// all the others
243-
static uint32_t spiDelayCyclesX4 = 4 * (F_CPU) / 1000000; // 4µs => 125khz
243+
static uint16_t spiDelayNS = 4000; // 4000ns => 125khz
244244

245245
static uint8_t spiTransferX(uint8_t b) { // using Mode 0
246246
int bits = 8;
@@ -249,12 +249,12 @@
249249
b <<= 1; // little setup time
250250

251251
WRITE(SD_SCK_PIN, HIGH);
252-
DELAY_CYCLES(spiDelayCyclesX4);
252+
DELAY_NS(spiDelayNS);
253253

254254
b |= (READ(SD_MISO_PIN) != 0);
255255

256256
WRITE(SD_SCK_PIN, LOW);
257-
DELAY_CYCLES(spiDelayCyclesX4);
257+
DELAY_NS(spiDelayNS);
258258
} while (--bits);
259259
return b;
260260
}
@@ -510,7 +510,7 @@
510510
spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
511511
break;
512512
default:
513-
spiDelayCyclesX4 = ((F_CPU) / 1000000) >> (6 - spiRate) << 2; // spiRate of 2 gives the maximum error with current CPU
513+
spiDelayNS = 4000 >> (6 - spiRate); // spiRate of 2 gives the maximum error with current CPU
514514
spiTransferTx = (pfnSpiTransfer)spiTransferX;
515515
spiTransferRx = (pfnSpiTransfer)spiTransferX;
516516
spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;

0 commit comments

Comments
 (0)