CAN Shield

The above is the latest revision of my code. I've added in an AutoBaud rate feature that works, but is a little clunky code wise. It requires that there are at least two active nodes on the bus, (not including the one you're using), and they must send messages at least every half second. It starts at a baud rate of 5kbps and goes up in increments of 5kbps until it reaches 1000kbps, (max rate for CAN V2.0B). This means that it could take nearly two minutes to detect the baud rate being used by the bus.

It does have a simple to use initialization routine though that simply requires a baud rate, (zero for AutoBaud), and a clock frequency, (frequency of MCP2515 oscillator, not Arduino). It then calculates out the proper bit timing for you.

Any comments or suggestions on the code would be welcome. Right now I'm waiting for a version 1.1 PCB, but I have the v1.0 shield pictured up and running just fine connected to SepEx motor controller at 125kbps. It happily streams data all day long. If the code doesn't work for you I'd be interested to know so that I can make it more universal.