Sketch can bus filter

hi everyone I have recently joined but have been following you for a long time I have an arduino uno and two can bus modules I need a hand I would like to create a sketch to be able to read everything from the network can filter what I need to modify a data and send everything that i receive with the modified data is it possible?

hello forgive me I'm new and so I still don't know how to do it I've tried many sketches and libraries but I can't understand how the filters work if maybe you can help me ?? it is an automotive application, but to simulate everything on the bench I am using an arduino module with two canbus modules one receives the signals in can from the instrument panel the other instead sends them to the bcm speed and 50kbps the filtering must be the following id 1e114003
practically I read 45 00 48 00 01 00 85 00 I should filter the 5 of the first two bytes becoming 0 in this case 40

I can take a picture of you but for now I'm trying to get two Arduino can bus modules to communicate with each other to understand how the filters work

this is only a link to see how the canbus filter works and how I can fix my problem but obviously it was not connected so when I try to connect the instrument panel I use an arduino with two canbus modules I would need a hand with some expert in the sector thanks

For starters you need your two modules to talk to each other. The various can libraries have examples that will do that. Get that working first. Filters as you know are built into the can controller, and the library should allow you to adjust them any way you want. What happens to a lot of first timers they get there transmitter to start sending then it quits, reset it and it does it again. Part of the CAN protocol is an ACK from another module. Without that ACK you will never get it running. You can set one up as a snooper but it will not transmit any data.

1 Like

ok thanks for the help. in fact first I wanted to understand how they work between them and the most logical thing to do and then I will try again with the inserted system. Do you have any library or example to send me? thanks for now

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

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string

#define CAN0_INT 2 // Set INT to pin 2
MCP_CAN CAN0(10); // Set CS to pin 9

void setup()
{
Serial.begin(9600);

if(CAN0.begin(MCP_ANY, CAN_50KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");

CAN0.setMode(MCP_STDEXT);

pinMode(CAN0_INT, INPUT);

CAN0.init_Mask(1,1,0x1FFFFFFF); // Init first mask...
CAN0.init_Filt(1,1,0x1E114000); // Init first filter...

Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read 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, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
else
  sprintf(msgString, "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();

}
}

for example so it should only read ext id 1E114000 instead it reads everything