MCP2515 Arduino Canbus module

Hello CanBus Geniuses,

Parts Used: Arduino Uno,
MCP2515

I have been messing around with the CanBus libraries that exist and have gotten to the point where i am outputting a 16 byte packet yet it does not correspond with the data which is supposed to be sent.

I want to send out a canmessage that ill eventually pick up with another module and arduino to print.

Notes: I use examples from libraries such as mcp_can without modifying them and just run, always get the same thing. Here are some pictures.


Any help is appreciated (i've rewired it a couple times and used 2 different arduinos and mcp2515 boards so unlikely they are faulty).

Thanks

Using the following code:

#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(10);


void setup() {
  canMsg1.can_id  = 0x0F6;
  canMsg1.can_dlc = 8;
  canMsg1.data[0] = 0x8E;
  canMsg1.data[1] = 0x87;
  canMsg1.data[2] = 0x32;
  canMsg1.data[3] = 0xFA;
  canMsg1.data[4] = 0x26;
  canMsg1.data[5] = 0x8E;
  canMsg1.data[6] = 0xBE;
  canMsg1.data[7] = 0x86;

  canMsg2.can_id  = 0x036;
  canMsg2.can_dlc = 8;
  canMsg2.data[0] = 0x0E;
  canMsg2.data[1] = 0x00;
  canMsg2.data[2] = 0x00;
  canMsg2.data[3] = 0x08;
  canMsg2.data[4] = 0x01;
  canMsg2.data[5] = 0x00;
  canMsg2.data[6] = 0x00;
  canMsg2.data[7] = 0xA0;
  
  while (!Serial);
  Serial.begin(115200);
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_125KBPS,MCP_8MHZ);
  mcp2515.setNormalMode();
  
  Serial.println("Example: Write to CAN");
}

void loop() {
  int error = mcp2515.sendMessage(&canMsg1);
  
  Serial.print("error1 :");
  Serial.println(error);
  error = mcp2515.sendMessage(&canMsg2);
  Serial.print("error2 :");
  Serial.println(error);

  Serial.println("Messages sent");
  
  delay(1000);
}

Serial monitor output:
16:31:04.410 -> Example: Write to CAN

16:31:04.410 -> error1 :0

16:31:04.410 -> error2 :0

16:31:04.410 -> Messages sent

16:31:05.408 -> error1 :0

16:31:05.408 -> error2 :2

16:31:05.408 -> Messages sent

16:31:06.413 -> error1 :2

16:31:06.413 -> error2 :2

And here are the error codes in the library:

    public:
        enum ERROR {
            ERROR_OK        = 0,
            ERROR_FAIL      = 1,
            ERROR_ALLTXBUSY = 2,
            ERROR_FAILINIT  = 3,
            ERROR_FAILTX    = 4,
            ERROR_NOMSG     = 5
        };

We could provide a more accurate answer if we had a schematic showing how everything is connected. Posting an annotated schematic would be very helpful.

I see several potential issues and will take a SWAG. The CAN bus is a differential bus, but your scope signal appears to be using two channels connected as single-ended( one on CAN High the other on CAN low). Additionally, CAN requires another module to acknowledge a sent message; loopback mode if used will only test the controller, not the actual bus.

Try fitting a jumper link between the pins of J1 on your MCP2515 module to connect the 120Ω load resistor R2.
You should see a better waveform.


wiring is as follows

do you know if their's a difference between using the 120 ohm vs a wire? i used a wire and it did nothing (i dont have the jumper, didn't come with one).

@hitacco , @yessirmillerbl,

Please read the personal message I have sent to both of you and respond.

Thank you.

@yessirmillerbl can you respond?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.