CANbus

CANbus

I have been experimenting with some CAN receiving hardware as part of the Open-CANDAQ project. I wanted to have an inexpensive CAN logging system that can handle full CAN frame rates, write to something like an SD card, potentially do some on the fly manipulation for display driving, and support networking for transfer of data.

An obvious choice is an ARM based Linux platform like the Raspberry Pi or the Beaglebone. The Pi doesn’t directly support CAN, but there are a number of aftermarket shields based around the MCP2515. TheMCP2515 is an CAN-SPI controller that is very easy to interface to. All it needs on the host microcontroller is an SPI port and a single interrupt pin.

One of the flaws of the MCP2515 is the lack of a FIFO buffer. It can only hold one message, and if you don’t get that message before the next one arrives, you will lose the new message. That means you need very fast interrupt response time.

I hooked up a Pi 3 + MCP2515 to my home CAN test network and did a bit of testing. I was surprised to see that if there is no additional load on the PI, it can in fact capture all the frames on a 99% saturated 1mbit CAN bus. I loaded the CANbus using a couple of copies of cangen and was able to capture 1 million frames without a single drop.

However if I added i/o load the pi ( either disk io or serial io), I started getting dropped frames. With a very full load I would miss over 25% of the frames. When I lowered the frame rate to 1ms frame interval (so ~1000 frames/sec down from ~7200 frames/sec full rate) it still dropped 10% of the frames. Even at 10ms frame interval it dropped 2%.

So, the MCP2515 is not a viable option. Fortunately Microchip knows this and has released a new MCP2517fd which has both a FIFO and CANFd support. There are not any shields yet with that chip, but I ordered 10 of the chips from Digikey and I’ll make a small test board once they get here. I suspect they will be sufficient for an load test case on a CAN bus, especially on a PI3 that has a quad core processor. If this works, it will make for a very cost effective CAN capture device.

Comments are closed.