Skip to content

Commit 344d70e

Browse files
committed
Fix CAN.begin() for MCP2515 with 8 MHz quartz by increasing the delay
1 parent bcdd7ac commit 344d70e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/MCP2515.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,15 @@ void MCP2515Class::reset()
433433
digitalWrite(_csPin, HIGH);
434434
SPI.endTransaction();
435435

436-
delayMicroseconds(10);
436+
// From the data sheet:
437+
// The OST keeps the device in a Reset state for 128 OSC1 clock cycles after
438+
// the occurrence of a Power-on Reset, SPI Reset, after the assertion of the
439+
// RESET pin, and after a wake-up from Sleep mode. It should be noted that no
440+
// SPI protocol operations should be attempted until after the OST has
441+
// expired.
442+
// We sleep for 160 cycles to match the old behavior with 16 MHz quartz, and
443+
// to be on the safe side for 8 MHz devices.
444+
delayMicroseconds(ceil(128 * 1000000.0 / _clockFrequency));
437445
}
438446

439447
void MCP2515Class::handleInterrupt()

0 commit comments

Comments
 (0)