Skip to main content
Jxu
Associate
November 22, 2019
Question

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

  • November 22, 2019
  • 12 replies
  • 8924 views

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.

 

This topic has been closed for replies.

12 replies

Tesla DeLorean
Guru
November 22, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jxu
JxuAuthor
Associate
November 23, 2019

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();

 }

}

Tesla DeLorean
Guru
November 23, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jxu
JxuAuthor
Associate
November 25, 2019

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.

Tesla DeLorean
Guru
November 25, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jxu
JxuAuthor
Associate
November 25, 2019

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).

Tesla DeLorean
Guru
November 25, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jxu
JxuAuthor
Associate
November 25, 2019

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.

Jxu
JxuAuthor
Associate
November 25, 2019

Thanks very much. I tried your code, it seems does not work, looks like it filter out ExtID = 0x0EAEC00 also.

I am going back to check the STM32f2xx_hal_can.c file date, it dated 2017, I am wondering is that the cause of out-dated file version?

Tesla DeLorean
Guru
November 25, 2019

Again this assumes the pattern you provided is correct, and why I suggested generating an actual list of whats on the wire to be filtered.

You could just go into a promiscuous mode, and filter the message at the software layer.

I've got no reason to believe the hardware is defective, or there being an unreported errata.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jxu
JxuAuthor
Associate
November 25, 2019

I tried get rid of "|8" from extid & mask, it seems works now. still do not know why, anyway thank for your great help !!!

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) ; // EXT

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

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

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

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

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