How to use the CAN-BUS shield?

Hey!

I just received my Can-Bus shield (v0.9b). I put it on a Leonardo and attached a CAN-Device to the CAN-Terminal. As written in the Wiki (seeedstudio.com/wiki/CAN-BUS_Shield) I installed the Can-Library into the library-directory of arduino 1.0.4 and tried to read from the device.

However, the “CAN.begin(CAN_125KBPS);” fails with the message

Enter setting mode fall
(typo in mcp_can.cpp)

The implementation looks like

(mcp_can.cpp l 297ff)

INT8U MCP_CAN::mcp2515_init(const INT8U canSpeed) { INT8U res; mcp2515_reset(); res = mcp2515_setCANCTRL_Mode(MODE_CONFIG); if(res > 0) { #if DEBUG_MODE Serial.print("Enter setting mode fall\r\n"); #endif return res; }"

As far as I understand, there was yet no communication with the device, so I wonder why the initialization fails. Is there something I have forgotten? What should happen during init if there is CAN device connected?

Nikolas

There is no communication with the CAN bus yet, however the Arduino is communicating with the MCP2515. Firstly, its putting the chip into a configuration mode then it would be setting the baud rate among other things.

That message seems to be related with the first part, setting the configuration mode.
If you go to the function mcp2515_setCANCTRL_Mode() in the library, it is setting the configuration mode then it reads the register back to check if it was properly set, if all is well it returns an OK status of ‘0.’

I would only have to guess something is not wired right, but you purchased a pre-assembled shield, right? I would hope they test those before shipping to a potential customer, but I have no clue and would have to guess the shield is at fault. If you have an ohm meter with a fine tipped probe, I would check for continuity of the MCP2515 to the shield pin to be sure that everything is fine before making that determination though…

Unless there is something different about the Leonardo that I’m unfamiliar with. I know it uses a chip different than the ATmega328. I’ve used this library on a Duemilanove-328 clone and an Uno using my home-made CAN bus shield with success and I have found a few bugs in the library that are unrelated to the issue you are experiencing. I’ll pull mine out and make sure its not sending out that message with 125KBPS; I use 250KBPS for my purposes.

I’ve tested 125KBPS with my interface and did not have the configuration fail. I’m still at the guess there is a wiring issue somewhere. Do you have anything else connected to your Arduino that would be using any of the SPI pins, like the Ethernet shield? It is more than certain the two shields would interfere if they share the same CS line.

While its a step ahead of your problem, I did have to tweek my library for 125KBPS to be read by my Peak-CAN USB interface that I have been using to test my shield and this library against.
In the ‘mcp_can_dfs.h’ file:

/* #define MCP_16MHz_125kBPS_CFG1 (0x01) #define MCP_16MHz_125kBPS_CFG2 (0xba) #define MCP_16MHz_125kBPS_CFG3 (0x07) */ #define MCP_16MHz_125kBPS_CFG1 (0x03) #define MCP_16MHz_125kBPS_CFG2 (0xb0) #define MCP_16MHz_125kBPS_CFG3 (0x06)
The commented-out section are the old values, the uncommented section allows my Peak-CAN interface to read what my CAN shield transmits and vice-versa.

Thank you for your ideas. I use the pre-assembled Can-Bus shield and have nothing else connected to my Leonardo. I’m not yet very familiar with the can stuff, so correct me if I am wrong:
The D9-connector is only for OBD2-stuff and uses two can pins and two others for GND and 12V. But if I just want to use can, I only have to attach CanHigh and CanLow to the green CanTerminal, right?

Can someone tell me what voltage I should get between the two Can-Lines if I don’t connect my Can-Device to the shield? I just want to check if maybe there is (also) an error on this side of the hardware.

//Update:
I switched to an Arduino Franzis (AtMega168) from an Arduino StarterKit and now I get

"Enter setting mode success
set rate success!!
Enter Normal Mode Success!!
CAN OPENED!
"

So there is either a problem with my Leonardo or with the Leonardo-Boards.

No problem!

The pinout of the DE9 connector is compatible with a pre-made OBD-II cable. The green terminals are there for flexibility.
I would still add a ground if I was able to but it is not necessary per the specification of the bus.

Check out this app note from Microchip, its pretty informative about the physical specifications of CAN.
http://ww1.microchip.com/downloads/en/appnotes/00228a.pdf

Awesome, that is what I like to see!

Actually, I just took a closer look at the Leonardo. The good news is, there is no problem with your Leonardo. However, with the bad news… the SPI pins are NOT connected to the digital IO pins that the shield uses and previous Arduino boards supported. I think you are better off using another Arduino board for this endeavor.

From: http://arduino.cc/en/Main/arduinoBoardLeonardo