adafruit / Adafruit_CircuitPython_MCP2515

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

Possible addition? #3

Open kdschlosser opened 3 years ago

kdschlosser commented 3 years ago

I have something that might be of interest that can expand this library so it can support the full gambit of bitrates the interface is able to do.

Right now the only bitrates that are supported are the ones that are in a hard coded table. The attached file calculates the bit timing registers using the bitrate as an input. It can also be tweaked by using the sample point and synchronization jump width as input parameters as well.

The code I wrote supports a bunch of different CAN interface chip families

can_bitrate.zip

I can do up a PR if it is something that would be added, just let me know.

ladyada commented 3 years ago

yes! PRs are welcome! here is a tutorial that can help https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

kdschlosser commented 3 years ago

It will be little while until I do any kind of a PR for this. I needed to be able to calculate the timing registers because of using a non standard bitrate. I figured instead of hard coding the timings into my code I would go this route. I still have to test out the library for functionality which won't be for a little while.

I am retrofitting my vehicles headlamps with curve adaptive and horizon adaptive HID's (2 projectors per headlamp). I have most of the mechanical aspects all sorted out and now I am putting together the code. It should hopefully be only a few days until I am done with the code portion of it then I have to put everything together and iron out any bugs.

The bitrate calculator above is a really important tool and makes it really easy for the user to be able to connect the interface. It also makes it easier to add bitrate discovery to make more of plug and play type of device.

because the most common use of CAN-Bus is in the automotive sector for vehicle diagnostics and communications you should consider putting together a library for OBDII vehicle communications. Other manufacturers of CAN interfaces provide at least a small code block that demonstrates how to use the interface with OBDII. This is something that I do have pretty extensive knowledge on and can put together if there is interest.

ladyada commented 3 years ago

sure, if someone would like to add support, we're happy to help and merge