Sparkfun CAN shield with Uno

Hi there,

I am trying to get the example code working with the following CAN shield: https://learn.sparkfun.com/tutorials/ca … -guide/all.

After getting the initialisation working with the Arduino UNO (actually not arduino but a knock off UNO), it doesn’t give me anything on the CAN analyser tool when I try to run the example code below:

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

//********************************Setup Loop*********************************//

void setup() {
  Serial.begin(9600);
  Serial.println("CAN Write - Testing transmission of CAN Bus messages");
  delay(1000);
  
  if(Canbus.init(CANSPEED_500))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");
    
  delay(1000);
}

//********************************Main Loop*********************************//

void loop() 
{
tCAN message;

        message.id = 0x631; //formatted in HEX
        message.header.rtr = 0;
        message.header.length = 8; //formatted in DEC
        message.data[0] = 0x40;
  message.data[1] = 0x05;
  message.data[2] = 0x30;
  message.data[3] = 0xFF; //formatted in HEX
  message.data[4] = 0x00;
  message.data[5] = 0x40;
  message.data[6] = 0x00;
  message.data[7] = 0x00;

mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
mcp2515_send_message(&message);

delay(1000);
}

Before you say the CAN analyser tool may be broken, I also tried with this code (https://github.com/coryjfowler/MCP_CAN_ … N_send.ino) from a different library and it gave me the error message in the arduino serial moniter “Error Sending Message…”.

I am using a female DB9 to DB9 cable from the CAN shield to the CAN analyser tool. Is it maybe that this is the problem? Do I have to reconfigure the jumpers in 6c here: https://learn.sparkfun.com/tutorials/ca … -guide/all ? If so, how exactly do I do that, it says something about soldering but it’s not quite clear to me how I should solder those pads.

Another idea I had was that the lack of termination resistors is causing the problem, because as far as I understand there are no termination resistors included in the shield, correct? If so, how do I add them if I want to use the DB9 cable to send receive?

Attached is a picture of my setup. There is an LCD attached, but it is not doing anything for the moment. Any help is greatly appreciated.

Try a 120 ohm resistor between the CAN_H and CAN_L pins on the board, if that doesn’t work, you might need to skip the DB9 and wire CAN_H, CAN_L and GND directly over to your CAN analyzer tool but keep the 120 ohm resistor connected as well.

Hi YellowDog,

thank you very much for the reply!

Do you mean like in the second image here: https://www.instructables.com/Sparkfun- … -Tutorial/, i.e. directly connected to RX and TX pins on the shield, or the pins from the shield’s DB9 port to the CAN analyser pins directly?

Cheers.

Update: It worked as shown in the link (https://www.instructables.com/Sparkfun- … -Tutorial/), I also connected my CAN analyser DB9 pins 2 and 7 to my own breadboard CAN bus with termination resistors and it worked. Thanks for your suggestions!