Skip to content

Fix CAN.begin() for MCP2515 with 8 MHz quartz by increasing the delay #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/MCP2515.cpp
Original file line number Diff line number Diff line change
@@ -433,7 +433,15 @@ void MCP2515Class::reset()
digitalWrite(_csPin, HIGH);
SPI.endTransaction();

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

void MCP2515Class::handleInterrupt()