Hello,
It's probably something simple, but I can't get a can bus filter working for message ID's 280 & 288, I can get the data from the car;
Standard ID: 0x280 DLC: 8 Data: 0x09 0x6D 0x00 0x00 0x4B 0x00 0x2D 0x4B
Standard ID: 0x4A8 DLC: 8 Data: 0xFF 0x7F 0x01 0x00 0x00 0x00 0x80 0x01
Standard ID: 0x0C2 DLC: 8 Data: 0x00 0x80 0x00 0x80 0x04 0x92 0x00 0x6D
Standard ID: 0x288 DLC: 8 Data: 0x0A 0x4E 0x10 0x00 0x00 0x82 0x92 0x5D
Standard ID: 0x5A0 DLC: 8 Data: 0x64 0x01 0x00 0x61 0xEC 0x01 0x00 0x2B
Standard ID: 0x1A0 DLC: 8 Data: 0x00 0x43 0x00 0x00 0xFE 0xFE 0x00 0x99
But when I try to apply a filter;
CAN0.init_Mask( 0, 1, 280 | 288 ); // Init first mask...
CAN0.init_Filt( 0, 1, 280 ); // Init 1st filter...
CAN0.init_Filt( 1, 1, 288 ); // Init 2nd filter...
I still get all the ID's data?
I tried the below as I read that all the masked & filters need to be populated;
CAN0.init_Mask( 0, 1, 280 | 288 ); // Init first mask...
CAN0.init_Filt( 0, 1, 280 ); // Init 1st filter...
CAN0.init_Filt( 1, 1, 288 ); // Init 2nd filter...
CAN0.init_Mask( 1, 1, 0b100011000 ); // Init first mask...
CAN0.init_Filt( 2, 1, 0b100011000 ); // Init 3rd filter...
CAN0.init_Filt( 3, 1, 0b100011000 ); // Init 4th filter...
CAN0.init_Filt( 4, 1, 0b100011000 ); // Init 5th filter...
CAN0.init_Filt( 5, 1, 0b100011000 ); // Init 6th filter...
Still didn't work.
I'm getting the;
Starting to Set Mask!
Setting Mask Successful!
Starting to Set Filter!
Setting Filter Successful!
Starting to Set Filter!
Setting Filter Successful!
messages OK.
Any advice would be most appreciated.
// CAN Receive Example
//
#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 10
void setup(){
Serial.begin(115200);
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data.
pinMode(2, INPUT); // Setting pin 2 for /INT input
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
Serial.println("MCP2515 Library Receive Example...");
CAN0.init_Mask( 0, 1, 280 | 288 ); // Init first mask...
CAN0.init_Filt( 0, 1, 280 ); // Init 1st filter...
CAN0.init_Filt( 1, 1, 288 ); // Init 2nd filter...
}
void loop()
{
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
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();
}
}