CAN Filtering¶
The CANlink® wireless 4000 is equipped with eight (8) hardware CAN filters, which can be configured to block certain CAN IDs received on the CAN bus from being sent wirelessly to connected peers.
Note
Only CAN messages coming in from a physical CAN bus are processed through the filter system, if enabled. If the message matches, it is transmitted to all wireless peers.
All messages arriving on a wireless interface are put onto the appropriate CAN bus.
Blocking certain CAN IDs can reduce the volume of CAN messages transmitted over the wireless interface, typically done for the purpose of not exceeding the maximum message processing throughput of the device, or ensuring that the CAN bus only transmits certain CAN messages to another segment of that CAN bus.
This can be particularly advantageous when multiple devices are connected simultaneously, as in a MultPoint or MultiTalk configuration.
(See MultiPoint Connections).
In addition, preventing certain CAN IDs being transmitted wirelessly can provide some security from eavesdroppers of sensitive wireless traffic.
CAN Filter Concepts¶
Each one of the eight filters can be configured to either
-
allow multiple CAN IDs to pass; or
-
allow a single CAN ID with optional downsampling.
A CAN message that does not match the receiver filter of an online CAN object is passed on to the next active (enabled) filter and checked again.
Only messages that match are transmitted.
Downsampling¶
Downsampling is the process of preventing every message that matches a particular Filter & Mask from being transmitted, but instead, waiting a minimum durtime period before sending the next matching message.
The period between volume of matching messages can be set with
-
0x5024 [CAN1 object min rec time]for CAN1 (and0x5025for the volatile version) -
0x5034 [CAN1 object min rec time]for CAN2 (and0x5035for the volatile version)
All of these objects can be individually set for each of the eight CAN filters, and specify the period in milliseconds before another message is permitted to pass that filter, and be transmitted wirelessly.
The default is 0, which allows every message that matches the filter to be transmitted.
Summary
- Downsampling allows slowing down the frequency of transmissions that match a certain filter.
- The default is set to
0, which allows every matched message to be transmitted. - The value determines the minimum time in milliseconds before another message matching that filter can be transmitted.
Precautions
-
If more than one message matches a particular filter (see Filter Mask), enabling Downsampling can lead to confusing wireless traffic where some matching messages are not transmitted, while others are, depending on the timing of those messages.
This results from the Downsampling period preventing any matching message from being transmitted until that period expires.
For this reason, it is recommended to enable Downsampling only on filters that match one specific CAN-ID. -
Since a non-matching CAN-ID does not remove the message from the filter checking process (it is passed onto the next active filter), a message that matches a filter but is within the Downsampling period may be matched by a subsequent filter.
This can give confusing results, if a CAN-ID matches a filter that has a Downsample period defined and is transmitted more frequently than that period.
Careful design of the Filters can be required for an optimal outcome.
Filter Mask¶
Filter for Multiple CAN IDs (abstracted example)¶
A filter configured to allow multiple IDs needs to define which binary values are allowed to pass through each CAN ID bit position.
Only when all CAN ID bits pass, the CAN message is permitted to be transmitted.
We can think of the filter bit positions being set to one of the following values
0only a value of0passes1only a value of1passes- X either value passes (we don't care)
In the following abstract examples, we use the following representations
| Result | Symbol |
|---|---|
| PASS | P |
| BLOCK | B |
| EITHER | X |
Example 1 Multiple CAN IDs (abstracted)¶
Pass only 0x200, and 0x201
| Filter | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | X |
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result : PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P |
| Overall Result : PASS |
| Rx CAN ID 0x000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | B | P | P | P | P | P | P | P | P | P |
| Overall Result : BLOCK |
| Rx CAN ID 0x001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | B | P | P | P | P | P | P | P | P | P |
| Overall Result: BLOCK |
Example 2 Multiple CAN IDs (abstracted)¶
Pass only 0x200 0x201, 0x000, and 0x001
| Filter | 0 | X | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | X |
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result PASS |
| Rx CAN ID 0x000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P |
| Overall Result PASS |
| Rx CAN ID 0x001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result PASS |
Special Case: Open Filter¶
With an open filter all incoming CAN messages are passed on to the processor regardless of their ID.
Either value passes off each bit passes the filter.
| Open Filter | X | X | X | X | X | X | X | X | X | X | X |
Filter for Single CAN ID (abstracted)¶
A filter configured to allow a single ID, needs to define the exact CAN ID, and whether any downsampling time is applied, i.e. the time for which messages will be blocked after receiving a single CAN message with this ID.
Example 3 Single CAN ID (abstracted)¶
Pass only 0x200
| Filter | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Downsampling Time | 0ms |
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P |
| Overall Result PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | B |
| Overall Result BLOCK |
Actual Filter Configuration Semantics¶
In the previous section it was discussed that there are essentially two
types of filters (multiple ID, single ID), but in fact each one of the
eight filters is configured via the following three (3) parameters
-
Filter Mask
Defines which received CAN ID bit positions are required to be checked against the same bit positions of the Filter ID (we call these bits "check Filter ID"), and which positions will be
regarded as "allowed to pass". -
Filter ID
For each bit position defined by the Filter Mask as "check Filter ID", the binary value of that position in the incoming CAN ID must match the binary value of the same position in the Filter ID, in
which case, the position will be regarded as "allowed to pass".
When each and every bit position of an incoming CAN ID is regarded as "allowed to pass", CAN messages with this CAN ID are passed onto the second stage of the filter, the Downsampling Time. -
Downsampling Time
The time the CAN receive channel remains closed after a single CAN message is received.
Example 4 Multiple CAN IDs (actual)¶
| Filter (abstracted) | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | X |
Pass only 0x200, and 0x201
| Filter Mask 0x7FE | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| Filter ID 0x200/0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0/1 |
| Downsampling Time | 0ms |
Messages
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | B | P | P | P | P | P | P | P | P | P |
| Overall Result:BLOCK |
| Rx CAN ID 0x001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | B | P | P | P | P | P | P | P | P | P |
| Overall Result:BLOCK |
Example 5 Multiple CAN IDs (actual)¶
Pass only 0x200 0x201, 0x000, and 0x001
| Filter (abstracted) | 0 | X | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | X |
| Filter Mask 0x7FE | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| Filter ID 0x200 0x201 0x000 0x001 |
0 | 0/1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0/1 |
| Downsampling Time | 0ms |
Messages
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
Filter for Single CAN ID (actual)¶
For single ID filter, the Mask is always configured to 0x7FF (11-bit IDs) or 0x1FFF FFFF (29-bit IDs).
Downsampling can optionally be set.
In practice, is it possible to configure downsampling for filters that allow multiple CAN IDs to pass, but there is little value in doing so since this would most probably result in some IDs never being received in a non deterministic manner.
Example 6 Single CAN ID (actual)¶
Pass only 0x200
| Filter Mask 0x7FF | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Filter ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Downsampling Time | 0ms |
Messages
| Rx CAN ID 0x200 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | P |
| Overall Result:PASS |
| Rx CAN ID 0x201 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| Individual Bit Results | P | P | P | P | P | P | P | P | P | P | B |
| Overall Result:BLOCK |
Filter Configuration Cases & Considerations¶
Eight (8) or fewer CAN IDs
If eight (8) or fewer CAN IDs are required to pass through the filters for the application at hand, the only consideration is to understand what is the maximum acceptable sampling time for each CAN ID and adjust the Downsampling Time accordingly.
Nine (9) or more CAN IDs
If nine (9) or more CAN IDs are required to pass through the filters, The situation is more complex, because apart from the CAN IDs required to pass, there would most probably be other CAN IDs passing that are not actually required to pass, which can compromise performance or communication cost.
In such cases it advisable to evaluate every non-required CAN ID against all filters and compile a list a of "non-required PASS CAN IDs" so that the total number of CAN IDs per second can be calculated.
Tip
If transmitting more than one CAN ID per filter, try to arrange each mask to have the fewest numbers of set bits. In this way, the matching IDs are more tightly grouped, and fewer unwanted messages would pass than having fewer filters with more bits set.
You may use the CAN ID_MaskGenerator.xlsx as a support to calculate a CAN receive filter mask for multiple CAN IDs Go to Download Center > 05_Utilities > 08_CAN ID Mask Generator.
Received CAN ID Evaluation¶
Rx CAN IDs are accepted (passed through the filter) if the following is TRUE
(Rx_ID & Filter_Mask) == (Filter_Mask & Filter_ID)
&: bitwise AND==: equality check
Configuring CAN Filters¶
The filters are located in the Object Dictionary at the following addresses.
They can be split into Volatile and Non-volatile objects.
Non-volatile CAN Filter objects:
| Location | Description |
|---|---|
0x5020 [CAN1 object filter settings] |
Non-volatile Receive Object ID |
0x5022 [CAN1 object mask settings] |
Non-volatile Receive Object ID Mask |
0x5024 [CAN1 object min rec time] |
Non-volatile Downsample time in ms |
0x5030 [CAN2 object filter settings] |
Non-volatile Receive Object ID |
0x5032 [CAN2 object mask settings] |
Non-volatile Receive Object ID Mask |
0x5034 [CAN2 object min rec time] |
Non-volatile Downsample time in ms |
Volatile CAN Filter objects:
| Location | Description |
|---|---|
0x5021 [Volatile CAN1 object filter settings] |
Receive Object ID settings that can be changed dynamically |
0x5023 [Volatile CAN1 object mask settings] |
Receive Object ID mask settings that can be changed dynamically |
0x5025 [Volatile CAN1 object min rec time] |
Downsample time in ms that can be changed dynamically |
0x5031 [Volatile CAN2 object filter settings] |
Receive Object ID settings that can be changed dynamically |
0x5033 [Volatile CAN2 object mask settings] |
Receive Object ID mask settings that can be changed dynamically |
0x5035 [Volatile CAN2 object min rec time] |
Downsample time in ms that can be changed dynamically |
Worked Examples¶
Given the information in this chapter, here we present an example of configuring several CAN filters.
We will configure only the non-volatile filters, but the principle is exactly the same for the volatile versions.
Points to remember¶
CAN object filter settings
These are the 0x50200x01 - 0x50200x08 (for CAN1), and 0x50300x01 - 0x50300x08 (for CAN2) objects.
- Bit 29 selects between an 11 and 29 CAN ID filter.
CAN object mask settings
These are the 0x50220x01 - 0x50220x08 (for CAN1), and 0x50320x01 - 0x50320x08 (for CAN2) objects.
-
If a bit in this object is set, the bit in the received message ID has to match the filter.
-
If a bit is reset (zero), the bit in the received message ID does not matter. ("Don't care").
CAN object min rec time
These are the 0x50240x01 - 0x50240x08 (for CAN1), and 0x50340x01 - 0x50340x08 (for CAN2) objects.
This object represents the minimum time period before allowing a subsequent message through the associated filter, in milliseconds.
If a message matches (and is therefore transmitted), at least this duration must past before another message that matches is transmitted.
This is also referred to as 'Downsampling'.
- If this value is set to 0, every message matching the filter will be received.
Tip
To prevent unintended data loss of other matching messages, only use Downsampling with filters for individual CAN identifiers.
Defaults
0x50200x01 [CAN1 object filter 0] is by default 0x00000000. This means all 11-bit CAN-IDs are matched.
0x50200x02 [CAN1 object filter 1] is by default 0x20000000. This means all 29-bit CAN-IDs are matched.
The rest of the filters are disabled with a 0x80000000. (Bit31 disables the filter when set).
0x50220x01 [CAN1 object mask 0] is by default 0x00000000. This means any value of the CAN-ID will be matched ("Don't care").
0x50220x02 [CAN1 object mask 1] is by default 0x00000000. This means any value of the CAN-ID will be matched ("Don't care").
So with the combination of these settings, every message will be matched, and therefore passed through to the wireless interface.
(The settings for CAN2 are exactly the same).
The following sub-section will permit only required messages through.
Worked Example One¶
CAN messages with a CAN identifier of 0x123 are received on the CAN bus.
These 0x123 messages match the filter, and are transmitted wirelessly.
All other CAN messages with a different CAN identifier are ignored and forwarded to the next filter for a possible match.
| Hex | Binary | |
|---|---|---|
| 11-bit CAN ID to match | 0x123 |
____ ____ ____ ____ ____ _001 0010 0011 |
| Filter | 0x123 |
0000 0000 0000 0000 0000 0001 0010 0011 |
| (match exactly this 11-bit message ID) | ||
| Mask | 0x07FF |
0000 0000 0000 0000 0000 0111 1111 1111 |
| (all bits must match) | ||
| Matching CAN messages | 0x123 |
0000 0000 0000 0000 0000 0001 0010 0011 |
| (transmitted) |
Configuration
-
Set
0x50200x01 [CAN1 object filter 0]to0x0000 0123 -
Set
0x50220x01 [CAN1 object mask 0]to0x0000 07FF
No specific Downsampling period is specified (the default is 0 which matches every message), so that is the complete filter configuration.
Worked Example Two¶
CAN messages with a CAN identifier of 0x123, 0x124 and 0x125 are received on the CAN bus.
We want to transmit all messages wirelessly.
All other CAN messages with a different CAN identifier are ignored and forwarded to the next filter.
| Hex | Binary | |
|---|---|---|
| 11-bit CAN ID to match | 0x123 |
____ ____ ____ ____ ____ _001 0010 0011 |
0x124 |
____ ____ ____ ____ ____ _001 0010 0100 |
|
0x125 |
____ ____ ____ ____ ____ _001 0010 0101 |
|
| Filter | 0x120 |
0000 0000 0000 0000 0000 0001 0010 0000 |
| Mask | 0x7F8 |
0000 0000 0000 0000 0000 0111 1111 1000 |
| (match these three 11-bit message IDs) | ||
| Matching CAN messages | 0x120 |
0000 0000 0000 0000 0000 0001 0010 0000 |
| (transmitted) | 0x121 |
____ ____ ____ ____ ____ _001 0010 0001 |
0x122 |
____ ____ ____ ____ ____ _001 0010 0010 |
|
0x123 |
____ ____ ____ ____ ____ _001 0010 0011 |
|
0x124 |
____ ____ ____ ____ ____ _001 0010 0100 |
|
0x125 |
____ ____ ____ ____ ____ _001 0010 0101 |
|
0x126 |
____ ____ ____ ____ ____ _001 0010 0110 |
|
0x127 |
____ ____ ____ ____ ____ _001 0010 0111 |
Configuration
-
Set
0x5020:0x01 [CAN1 object filter 0]to0x0000 0123
Because bit 29 is reset (value of0), this means the message is interpreted as an 11-bit CAN-ID.
This influences what we can use for the Mask value. -
Set
0x5022:0x01 [CAN1 object mask 0]to0x0000 07F8
Since the corresponding filter is defined for an 11-bit CAN-ID, we can leave the higher bits as0, because only 11-bit CAN-IDs will match.
No Downsampling is specified, so that is the complete filter configuration.
It can be seen that since the inverse of the mask 0x7F8 is 0x007, eight messages will be matched by this configuration, rather than our required three.
If this is not acceptable, a separate filter could be created for just the 0x123 message, as shown in Worked Example One, and another one for 0x124 and 0x125 with a mask of 0x7FC (111 1111 1100).