CAN Bus bridge - can't pass messages between two interfaces

Hello everyone!

I hope someone can give me an advice.

I'm making a simple CAN-Bridge between a can-bus of my car and one of the modules. I'm using a Arduino Uno and a Dual_CAN hat with two mcp2515 can-controllers. First controller (CAN0) is connected to digital pins 10 and 2, second (CAN1) - to pins 9 and 3. Second has the 120 Ohm resistor connected as required.
Everything seems to work fine: if I connect a car's can-bus to any interface - I can see messages no problem.
But, the problem is: I'm not getting any messages from the connected module and no messages are being passed from one interface to another.
I'm trying to make it work for a week now to no avail, banging my head against the wall already - I just don't know what is wrong.

The sketch that I'm using is based on an example from MCP_CAN library. Temporarily, I've added code to forward messages from each interface to console to see what's going on:


#include <mcp_can.h>
#include <SPI.h>

unsigned long rxId;
byte len;
byte rxBuf[8];
char msgString[128];

MCP_CAN CAN0(10);                              // CAN0 interface usins CS on digital pin 10
MCP_CAN CAN1(9);                               // CAN1 interface using CS on digital pin 9

void setup()
{
  Serial.begin(115200);
  
  // init CAN0 bus, baudrate: 100k@16MHz
  if(CAN0.begin(MCP_NORMAL, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
  Serial.print("CAN0: Init OK!\r\n");
  CAN0.setMode(MCP_NORMAL);
  } else Serial.print("CAN0: Init Fail!!!\r\n");
  
  // init CAN1 bus, baudrate: 100k@16MHz
  if(CAN1.begin(MCP_NORMAL, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
  Serial.print("CAN1: Init OK!\r\n");
  CAN1.setMode(MCP_NORMAL);
  } else Serial.print("CAN1: Init Fail!!!\r\n");
  
  SPI.setClockDivider(SPI_CLOCK_DIV2);         // Set SPI to run at 8MHz (16MHz / 2 = 8 MHz)
  
}

void loop(){  
  if(!digitalRead(2)){                         // If CAN0 pin 2 is low, read CAN0 receive buffer
    
    CAN0.readMsgBuf(&rxId, &len, rxBuf);       // Read data: len = data length, buf = data byte(s)

    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "CAN0 Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      sprintf(msgString, "CAN0 Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);
  
    Serial.print(msgString);
  
    if((rxId & 0x40000000) == 0x40000000){    // Determine if message is a remote request frame.
      sprintf(msgString, " REMOTE REQUEST FRAME");
      Serial.print(msgString);
    } else {
      for(byte i = 0; i<len; i++){
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
        Serial.print(msgString);
      }
    }
        
    Serial.println();
    
    CAN1.sendMsgBuf(rxId, 0, len, rxBuf);      // Immediately send message out CAN1 interface
  }

  if(!digitalRead(3)){                         // If CAN1 pin 3 is low, read CAN1 receive buffer
    CAN1.readMsgBuf(&rxId, &len, rxBuf);       // Read data: len = data length, buf = data byte(s)

    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "CAN1 Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      sprintf(msgString, "CAN1 Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);
  
    Serial.print(msgString);
  
    if((rxId & 0x40000000) == 0x40000000){    // Determine if message is a remote request frame.
      sprintf(msgString, " REMOTE REQUEST FRAME");
      Serial.print(msgString);
    } else {
      for(byte i = 0; i<len; i++){
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
        Serial.print(msgString);
      }
    }
        
    Serial.println();
    
    CAN0.sendMsgBuf(rxId, 0, len, rxBuf);      // Immediately send message out CAN0 interface
   }

}

So maybe someone have any knowledge about this topic, so I could rule out at-least a sw part. I would greatly appreciate any input!

Description is good.

Poetry, always risky. Schematics are preferred.

Too much poetry. What are You talking about ? Know that every helper is a complete newbie to Your project. Draw a logic block diagram showing things. Arrows for messages sent etc.

A week? Keep on trying! Using 3 weeks full time or a hole year of hobby time..... Then You can say You have been trying.

Summing up. Step down and give a description from the bottom. What and how are You trying to do things?

Post an annotated schematic as to how you have actually wired it. Be sure to show all power, ground connections as well as all termination resistors and their value. Post a list of the messages you are working with and also if there are OEM, Diagnostic or Dealer messages and how you are accessing them. By design messages are restricted and generally not available to just anything that is placed on the bus. The OEMs spent years with many engineers putting this together and documenting it. How much of that have you read. That would take several weeks in itself. Which module are you working with, they are not all the same and what year, model, make vehicle is this?

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