MCP 2515 CAN data filtering

I have been looking through the forum and have not be able to find anyone with my issue. I am filtering CAN id' s and only need to look at 2 and got that working. I am trying to now make conditional statements from data bytes in the can ID. the rxBuf [3] is from ID 0x18FF81 and the rxBuf[7] is from ID 0x18FF62 but the send data will change if either rxBuf3 and 7 are true

void loop()
{
{

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(( rxBuf[3] == 0xC1) && (A == !prevA))
{
byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC100);
A = true;
}
if( (rxBuf[3] == 0xC0) )
{
byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, HOGoff);
A = false;
}
Serial.print("A");
Serial.print(A);

if((rxBuf[7] == 01) && (A == true) ) {

byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC100);

}
if(rxBuf[7] == 02 && (A == true) ) {

byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC75);

}

if(rxBuf[7] == 03 && (A == true) ) {

byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC50);

}
if((rxBuf[7] == 04) && (A == true)) {

byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC20);

}
delay(20); // send data

Serial.println();
}
}

Never post code in pictures! Use code tags (the </>-button in the editor) and post complete code.

dskelton56:
[...] the rxBuf [3] is from ID 0x18FF81 and the rxBuf[7] is from ID 0x18FF62 [...]

The array "rxBuf" is the CAN message buffer created for the receive function in your sketch. The contents of that array are overwritten with each received CAN message and no sub contents of the array correspond to any specific IDs.

coryjfowler:
The array "rxBuf" is the CAN message buffer created for the receive function in your sketch. The contents of that array are overwritten with each received CAN message and no sub contents of the array correspond to any specific IDs.

Is it possible to take the received CAN message and store the ID to add to the conditional statements? I have tried this by creating a variable and in the condition comparing the rxId to the variable

int A = 0;
int Mud = 0xFF81;
int prevA = 1;

MCP_CAN CAN0(10);

I have also just hard codded the ID into the code and that didnt seem to work either

           if((rxId == 0x18FF62) && (rxBuf[7] == 01) && (A == true) ) {
        
              byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC100);

I think I just figured it out. I was looking at the if statement from your example and used the 0x8000000 but included my ID.

            if(((rxId & 0x18FF62A4 ) == 0x18FF62A4   ) && (rxBuf[7] == 03 && (A == true) )) {

              byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC50);
          
        }
            if(((rxId & 0x18FF62A4 ) == 0x18FF62A4   ) && (rxBuf[7] == 04) && (A == true)) {

             byte sndStat = CAN0.sendMsgBuf(0x1CFF0105, 1, 8, TC20);

Thank you for taking the time to read and help out with my issue

dskelton56:

(rxId & 0x18FF62A4)

You dont want to do that.

This (rxId & 0x80000000) is masking that specific bit so I can check whether or not that specific bit is set. You want to check against the full ID, so you would need to mask off all possible ID bits which for extended IDs is 29 bits or 0x1FFFFFFF.

Thus:if(((rxId & 0x1FFFFFFF ) == 0x18FF62A4  ) [...]

Thank you