2017-02-21 01:06 AM
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.
2017-02-21 03:54 AM
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
2017-02-21 05:27 AM
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;2017-02-21 06:48 AM
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.
2017-02-21 07:01 AM
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.
2017-02-22 08:35 AM
In the worst case scenario you can read the manual and CAN register documentation, and program the filter registers directly, and understand the settings that are working. I believe these should be fairly easy to reconfigure on the fly, but I'm not offering to dissect HAL to figure it out.
I'd be wary that
Data[3] is 8-bit wide, and the ID is 11-bit, and frankly you're using 32-bit mode, where presumably all the bits need to match across the whole header. You are programming only one 16-bit register. Perhaps think about this a bit harder, and if you need to be programming more registers, and if masking the bits you want to match on is a more appropriate route.