Howdy. I have a pair of Leonardo’s; they are each attached to a CAN-BUS shield board. The code I am running is the CAN_Read_demo on one shield/Leonardo pair and CAN_Write_demo on the other shield/Leonardo pair. The two systems are connected via the CANH/CANL pinholes available on the shield (I have not connected the GND and 5V pinholes as both systems are connected to teh same PC via USB and thus share the same power and ground). I am unable to write anything on the CAN bus (ie. mcp2515_send_message() always returns a zero value); when I look at the mcp2515 library which underlies this example code, it appears that reading the 8-bit registers seems to only return 0xff values. I suspect my SPI bus setup is somehow flawed. Is that possible?
The code I am running does not call pinMode() for any Leonardo pins; should I be doing something explicit steps (or wiring) to enable the Leonardo to chat usefully with the CAN-BUS shield? Might I be missing anything else?
Or should this CANbus read/write example code “just work” in this rig?
Thanks.
Hello, and thanks for using the forums!
Unfortunately the CAN Bus Shield is not compatible with the Arduino Leonardo. The Leonardo puts it’s SPI pins in a different place than the shield is expecting. Additionally, our library is hard coded to the ATmega328 processor found on an Uno board and isn’t SPI compatible with the ATmega32U4 found on a Leonardo. It could be made to work, but would take quite a bit of re-wiring and modification to the libraries and that’s beyond the scope of what we can help with.
We recommend using this shield with an [Arduino Uno or [SparkFun RedBoard.](https://www.sparkfun.com/products/13975)](Arduino Uno - R3 SMD - DEV-11224 - SparkFun Electronics)
Ah. Well, that would explain much. Thanks for the helpful reply. I suspect it may be useful to others to put this information about restrictions-of-use regarding the CAN-BUS shield in a prominent place on the CAN-BUS shield product page.
Thanks again.
I now have the indicated RedBoards and have coupled one ReadBoard to each of my Can-BUS Shields. I have wired the setup so that: (1) all systems are powered by USB from the same PC (which gives me a common ground) and have wired, between the Shields, CANH to CANH and CANL to CANL. No other wiring was done between the Shields. The RedBoards are noted as Arduino Uno’s in the IDE setup.
The good news is the code gets further: the init functions finish successfully. The bad news is no CAN traffic is observed; that is, the examples still do not work. This is still a bust…there’s no communication.
It sounds like you’re missing termination on either end of your CAN bus.
Try connecting a 120 ohm resistor across CAN_H and CAN_L on either end of you CAN bus and that should bring things to life.
here is the error:
C:\Arduino\SparkFun_CAN-Bus_Arduino_Library-master\examples\CAN_Write_Demo/CAN_Write_Demo.ino:24: undefined reference to `Canbus’
C:\Arduino\SparkFun_CAN-Bus_Arduino_Library-master\examples\CAN_Write_Demo/CAN_Write_Demo.ino:24: undefined reference to `Canbus’
C:\Arduino\SparkFun_CAN-Bus_Arduino_Library-master\examples\CAN_Write_Demo/CAN_Write_Demo.ino:24: undefined reference to `CanbusClass::init(unsigned char)’
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
What should i do?