Skip to main content
jerzy
Associate II
February 21, 2017
Question

STM32F1 how to configure CAN filters in ID List mode?

  • February 21, 2017
  • 5 replies
  • 3970 views

Posted on February 21, 2017 at 10:06

I can configure CAN filters from main.c file, but I want also to configure them by sending frame from the other node. It's that even possible to configure CAN filters while STM is working? There is the code from interrupt to configure filters:

HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);

sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.BankNumber = hcan.pRxMsg->Data[1];

sFilterConfig.FilterNumber = hcan.pRxMsg->Data[2];

sFilterConfig.FilterIdHigh = (hcan.pRxMsg->Data[3])<<5;

sFilterConfig.FilterIdLow = 0;

sFilterConfig.FilterMaskIdHigh = 0;

sFilterConfig.FilterMaskIdLow = 0;

sFilterConfig.FilterFIFOAssignment = 0;

sFilterConfig.FilterActivation = ENABLE;

HAL_CAN_ConfigFilter(&hcan, &sFilterConfig);

For example I am sending Data[1] = 1, Data[2]=0.

When I'am sending the frame, the LED changes it's state, so it should work. I used analogous code in main.c file to configure filter while programming STM. It's possible to solve this?

Update: I can configure them from interrupt but in filter mask mode. So the issue is how to configure them in ID list mode. 

This topic has been closed for replies.

5 replies

Oliver Beirne
Associate II
February 21, 2017

Posted on February 21, 2017 at 12:54

Hello

I have moved your question to the

https://community.st.com/s/topic/0TO0X000000BSqSWAW/

‌ where someone should be able to assist you.

Thanks

Oli

T J
Senior III
February 21, 2017
Posted on February 21, 2017 at 14:27

hi,

CAN filters are a little difficult to understand;  this is about the 11bit addressing mode filter (0x0000 - 0x07FF)

This example below works for any address that fits the mask 0x0700 with a 0x01?? address;

Frames will be received, from any address that has 0x01??    (ie 0x0100 to 0x01FF)

functionally;

filter Mask = 0x0700;      <- only these 3 bits are tested

filter ID = 0x0100;          <- acceptable addresses must comply with this value over those 3 bits in the filter mask.

all frames that do comply with this filter, will be sent into FIFO 0; (FilterFIFOAssignment)

(since the filter registers are 32bit long, the actual bit position of the mask is moved up 5 bits.)

implementation;

//##-2- Configure the CAN Filter ###########################################

  sFilterConfig.FilterNumber                     = 0;

  sFilterConfig.FilterMode                       = CAN_FILTERMODE_IDMASK;

  sFilterConfig.FilterScale                      = CAN_FILTERSCALE_32BIT;

  sFilterConfig.FilterIdHigh                     = 0x100 << 5;  //11-bit ID, in top bits

  sFilterConfig.FilterIdLow                      = 0x0000;

  sFilterConfig.FilterMaskIdHigh            = 0x700 << 5;    // resolves as 0x01xx

  sFilterConfig.FilterMaskIdLow                = 0x0000;

  sFilterConfig.FilterFIFOAssignment    = 0;

  sFilterConfig.FilterActivation          = ENABLE;
jerzy
jerzyAuthor
Associate II
February 21, 2017
Posted on February 21, 2017 at 14:48

Thanks for reply,

I understand how to set filters in Mask mode, but I want to use ID list mode there. The problem is that initialization does not occur from the interrupt.

T J
Senior III
February 21, 2017
Posted on February 21, 2017 at 15:01

I can only help with my stuff that works.

did you try to find further examples within this site ?

there are many to check, if you can search with the correct tags.