I wonder if is possible to adapt a low speed fault tolerant CAN network (100kbps) to a high speed CAN network. I need this to connect a newer infotainment board (CIC) to my K-CAN inside my BMW e60 car. I already managed to wake up and control (on a workbench) the CIC via Arduino and MCP2515 shield. Do you have any idea if is possible ? Thanks!
1 Answers
The easiest thing to do is probably to simply replace the CAN transceiver IC on the infotainment board you're putting into the car, to one that matches the bus type you already have in the car. The different transceiver ICs are usually drop-in replaceable, so no problem with that.
However, even with a matching transceiver, the data bit rate needs to match as well, so you need to determine the bit rate used by the board and the one used by the vehicle's bus.
If the bit rates don't match, there's no point in replacing the transceiver IC - in this case the only solution is probably to create a bidirectional store-and-forward adapter/gateway.
One may construct such a gateway using an Arduino, but it'd have to have two CAN bus "shield" daughter boards - one for each bus, where each daughter board carries a CAN transceiver appropriate for the bus it'd connect to, and its CAN controller configured to the appropriate bit rate.
Each of the CAN controllers connects to the Arduino via SPI. It is very much possible for multiple slave devices to share a single SPI bus, with the master device (e.g., the Arduino microcontroller) selecting the device it wishes to communicate with using the chip/slave select (CS/SS) lines. For more information about SPI communication, including multi-slave, see here and here.
For off-the-shelf Arduino "shields" relying on SPI, additional shields (beyond the first) might requires physical rerouting of their CS/SS line to a different control line coming from the Arduino microcontroller, to allow slave selection. Consult the boards' pinouts and/or schematics to determine which modifications are required. Specifically, if using seeed's CAN bus circuit, check the "CS pin" section of its Wiki.
In terms of software, the gateway would basically need to constantly copy messages received in one bus to the other, with a small FIFO buffer to keep a few messages in case the target bus is busy. Some modifications to the CAN bus library's source code might be required, to support multiple CAN controllers and switching between them using the CS/SS lines.
BTW, Stack Overflow is probably the wrong place for this question, as it's not really a programming question.
-
Thank you for your response! Meanwhile I've learned that it can be done as you said with 2 CAN shields but the Arduino board must support 2 SPIs. – SXN Nov 15 '16 at 21:26
-
@SXN, you can connect multiple devices a single SPI bus, using the chip/slave select (CS/SS) line to select the device you wish to communicate with. Check in the schematics of the "shield" how to reroute a different data pin to the MCP2515's CS line on the 2nd shield. If you're using seeed's CAN bus circuit, check the "CS pin" section of http://wiki.seeed.cc/CAN-BUS_Shield_V1.2/ You'll also need to modify the CAN bus library source code to adapt for the 2nd device. – Sagie Nov 15 '16 at 22:56
-
@SXN see also http://tronixstuff.com/2011/05/13/tutorial-arduino-and-the-spi-bus/ , where there are some explanations about multiple slaves on a single SPI bus. – Sagie Nov 15 '16 at 23:00