adafruit / Adafruit_CircuitPython_MCP2515

A CircuitPython library for working with the MCP2515 CAN bus controller
MIT License
20 stars 14 forks source link

Adding support for 12Mhz crystal oscillator in __init__.py #26

Open srolf opened 3 weeks ago

srolf commented 3 weeks ago

Please add in init.py support for a crystal oscillator running at 12Mhz.

I would like to use on a WaveShare RP2040-PiZero with a WaveShare RS485 CAN HAT for Raspberry Pi which uses a 12Mhz oscillator. This HAT exists in two variants, one with 8Mhz and one with 12Mhz.

srolf commented 3 weeks ago

As mentioned in the code, I used the CAN bus timing calculator and inserted before the 10Mhz definition the following:

    # 12MHz Crystal oscillator (used on the WaveShare RS485 CAN HAT)
    12000000: {
        #        CNF1, CNF2, CNF3
        1000000: (0x00, 0x88, 0x01),
        500000: (0x00, 0x9A, 0x03),
        250000: (0x00, 0xBF, 0x06),
        200000: (0x02, 0x92, 0x02),
        125000: (0x01, 0xBF, 0x06), 
        100000: (0x02, 0xB5, 0x05),
    },

and was able to receive frames with correct data on a RPi5 with a CAN-USB dongle (USB ID 1d50:606f) at 500K and 1M.