Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timurrrr
Copy link

Hi!

I bought a few MCP2515 from Amazon and they all came with 8 MHz quartz crystal.
Whenever I called CAN.begin(), it would return 0.
I was sure I set all the configuration parameters correctly before calling it.

It took me some time to debug, but then I started reading the datasheet [1] and found section 8.1 that says

8.1 Oscillator Start-up Timer
The MCP2515 utilizes an Oscillator Start-up Timer
(OST) that holds the MCP2515 in Reset to ensure that
the oscillator has stabilized before the internal state
machine begins to operate. 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.

There is a delayMicroseconds(10); inside MCP2515Class::reset(), but some quick math reveals that 128 clock cycles of a 8 MHz clock is 16 microseconds. Indeed, changing the value from 10 to 16 makes CAN.begin() work for me.

[1] http://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf

@utkarshsethi
Copy link

Is this not solved by #set-clock-frequency?

@leftCoast
Copy link

Just Ran into this delay issue hooking a teensy 3.2 to a board with 2515 on it. 10 microseconds fails. 15-20 runs fine. Have not tried this with anything else on the SPI bus as yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants