MCP2515 Dual Can Setup Problems

Hi, i am developing module to filter one ID and replace some data of the message that goes to the cluster and sent it back, all the code is working and tested, but i have some type of issue.

My code: Using CoryJFowler MCP_Can libraries with arduino nano.

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

unsigned long rxId;
unsigned long rxId_Filter;

/////////////
unsigned char flagRecv = 0;
//unsigned char len = 0;
unsigned char buf[8];
char str[20];

byte len;
byte rxBuf[8];


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

#define CAN0_INT 2                              // Set INT to pin 2
#define CAN1_INT 3                              // Set INT to pin 3

void setup()
{
  Serial.begin(115200);
  
  // iniciar CAN0 bus, baudrate: 100k@8MHz
  if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_8MHZ) == CAN_OK){ //MCP_EXT Vs MCP_ANY?
  Serial.print("CAN0: Arranque OK!\r\n");
  CAN0.setMode(MCP_NORMAL);
  } else Serial.print("CAN0: Arranque Falhou!!!\r\n");
  
  // iniciar CAN1 bus, baudrate: 100k@8MHz
  if(CAN1.begin(MCP_ANY, CAN_100KBPS, MCP_8MHZ) == CAN_OK){
  Serial.print("CAN1: Arranque OK!\r\n");
  CAN1.setMode(MCP_NORMAL);
  } else Serial.print("CAN1: Arranque Falhou!!!\r\n");

  SPI.setClockDivider(SPI_CLOCK_DIV2);         // Set SPI to run at 8MHz (16MHz / 2 = 8 MHz)
  
  Serial.end();

  rxId_Filter = 0x100;

 
}


void loop(){

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

      CAN0.sendMsgBuf(rxId, 0, len, rxBuf);      // Immediately send message out CAN1 interface

    }
    else
    {
{
  
      if (rxBuf[1] == 0xFF)
      {
      
        byte data[8] = { rxBuf[0], rxBuf[0], rxBuf[2], rxBuf[3], rxBuf[4], rxBuf[5], rxBuf[6], rxBuf[7] };
        CAN0.sendMsgBuf(rxId, 0, len, data );
      }
     }
    }
  }
  
   
  
  if(!digitalRead(CAN0_INT)){                         // If pin 3 is low, read CAN1 receive buffer
    CAN0.readMsgBuf(&rxId, &len, rxBuf);       // Read data: len = data length, buf = data byte(s)
     CAN1.sendMsgBuf(rxId, 0, len, rxBuf);      // Immediately send message out CAN1 interface

    }
    }

I am using this on my bmw, the module is conected between the cluster and factory can lines, and when i conect it to the can network, cluster work but i can not make diagonostics on my obd port, because it stop working. When i measure the can lines without the module it measures 0.2 to 0.25v and 4.8 to 4.75v, when conected it measures 0.35 to 0.4 and 4.6 to 4.65v. Only way i can make all work is if dont sent messages back from the cluster out of can 1, that way i have fully working obd diagonistics, but i can not see the cluster on modules list, because return messages are not been sent, and that way i can not comunicate with cluster on obd port, i can comunicate with all the other modules. Seems like can 1 is senting back messages that it is creating some type of problem like repeted data on can network. If anyone can help me will be good because i lost almost 2 weeks trying to understand the problem and i can not work out the problem. sry my english

I will take a SWAG and say those messages may not be available to you. Many times the OBD CAN goes through a gateway which restricts messages. They may also be limited by other means. There were 3 classes of messages for OBDII, this may have changed I am not current. They were OEM only, Dealer, OEM only, and CARB other messages that are required. I have a feeling where the odometer readings are stored which by law cannot be changed.

I dont read or modify any messages on OBD, messages changes are all made on the internal can of the car, not on obd can, when obd stop working is bacause the internal can have too much data that should not have, and the body module can not handle that and make obd not working. I can modify anything on the cluster with just can messages, including odometer. My problem is how i can make arduino not sent repeted messages back, because seems like all the data that i sent to cluster it than sent back again to the can on diferent time wich make can bus fail.

I was able to make it work, it take a good amount of work, i basic have compare the can network with cluster instaled and removed, with diagnonostics on anf off to be able to compare all the ids and see the diferences and identify the ids that i need to return back to can network from my cluster. that way i do not make a mess on the can network and everything work like expected. I can know make diagostics with no errors and i can see my cluster on the diagonostics.

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