cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the STM32F205 Canbus ID filter? it seems like it does not works as rule:

Jxu
Associate II

CAN Bus filter Rules:

  The filter mask is used to determine which bits in the identifier of the received frame are compared with the filter

   If a mask bit is set to a zero, the corresponding ID bit will automatically be accepted, regardless of the value of the filter bit.

   If a mask bit is set to a one, the corresponding ID bit will be compare with the value of the filter bit; if they match it is accepted otherwise the frame is rejected.

 

12 REPLIES 12

So provide a case demonstrating the failure, including both the settings for the filter(s) and the data you believe is non-conforming.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Jxu
Associate II

I tried to configure CAN ID filter to only allow ID = xxEAECxx to go through CAN2

static void CAN_Filter(void)

{

CAN_FilterConfTypeDef sFilterConfig;

sFilterConfig.FilterNumber = 14; //0-13: CAN1, 14-27:CAN2

 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh = 0x00EA;

 sFilterConfig.FilterIdLow = 0xEC00;

 sFilterConfig.FilterMaskIdHigh = 0x00FF;

sFilterConfig.FilterMaskIdLow = 0xFF00; 

 sFilterConfig.FilterFIFOAssignment = 0;

 sFilterConfig.FilterActivation = ENABLE;

 sFilterConfig.BankNumber = 0;

  

 if(HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)

 {

  /* Filter configuration Error */

  Error_Handler();

 }

}

Is that a Standard or Extended ID? What is the ID you're trying to match?

I know you've given me a mask, but I'm try to understand the end-to-end consequence, and if your initial logic is correct, or not.

Are you getting any messages with this?

CAN2 will only work if CAN1 is functional.

0690X00000AroXBQAZ.jpg

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Jxu
Associate II

Right now, I use CAN2 as slave communication and it works fine. the only thing I need to do is filter out some none-related CanID,

I use Extended ID, I want to only allow ID format xxEAECxx to pass through, which means 2nd and 3rd byte is EAEC.

Ok, lets try this experiment.

Enable the reception of ALL messages, print the StdID and ExtID of all those messages, provide this list, identifying the specific messages you want to accept with your filter.

#UpHillSkiing

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Jxu
Associate II

That is not possible due to the unknown Canbus ID condition, Because my device's source Address=0xEC, so I only need to take care of any message contains source address 0xEC which is Extended ID format: xxxxECxx (xx means any hex value).

You can either receive messages or you can't, the CAN controller can see all the packets on the wire. Going to call non-sense on that.

Pretty sure that's not the right bit position for the Source Address, nor PDU Specific/Format, in the J1939 sense. I'd also filter on the IDE designation.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Jxu
Associate II

Sorry, that's my mistake, I need filter PDU and destination Address (not source Address), because my device only care the message from Master contains with PDU and destination address of my device, for example: any message on the Canbus line with destination address not equal my device (0xEC) will be filtered out. my device does not communicate with other slave device, only communicated with Master controller.

uint32 extid = 0x0EAEC00; // 00=Source ID EXTID[7..0], EC=PDU Specifc EXTID[15..8], EA=PDU Format EXID[23..16]

uint32 mask = 0x0FFFF00; // Ignore EXTID[7..0]/EXID[28..24], Pass EXTID[23..8]

extid = (extid << 3) | 4; // EXT

mask = (mask << 3) | 4; // IDE=1

sFilterConfig.FilterIdHigh = (extid >> 16) & 0xFFFF;

sFilterConfig.FilterIdLow = (extid >> 0) & 0xFFFF;

sFilterConfig.FilterMaskIdHigh = (mask >> 16) & 0xFFFF;

sFilterConfig.FilterMaskIdLow = (mask >> 0) & 0xFFFF; 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..