Description
disableFilter( num, ext )
– disables the CAN-filter number num
. It does not change any settings of the filter but only disables it. Use init_FiltID() or init_FiltRang() set it back into operation.
Syntax
MCAN0.disableFilter( num, ext )
Parameters
uint8_t num– filter number – Standard 11bit: FILTER_0
, FILTER_1
. . . FILTER_7
) or
– Extended 29bit: FILTER_EXT_0
, FILTER_EXT_1
. . . FILTER_EXT_7
)
uint8_t ext – extended ID – 0
for a Standard 11bit ID filter definition
– 1
for an Extended 29 bit ID filter definition
Returns
nothing
Example Code
The following example receives messages on the CAN bus (MCAN0).
void setup()
{
while(!Serial);
Serial.println("Example filtering CAN messages");
// Add a Range filter of extended IDs
MCAN0.init_FiltRang(FILTER_EXT_0, 1 , 0x7000, 0x8000);
// Disable the pre-configured FILTER_0 to not receive all std. msg. anymore
MCAN0.disableFilter(FILTER_0, 0);
}
void loop()
{
if( MCAN0.checkReceive() )
{
CANMessage t_canMesgToRecv;
if(MCAN0.readMsgBuf( t_canMesgToRecv ) == CAN_OK)
Serial.println(t_canMesgToRecv.toString());
}
}
Notes and Warnings
At start-up, the filters FILTER_0 and FILTER_EXT_0 are pre-configured to receive all standard (FILTER_0) and all extended IDs (FILTER_EXT_0). Please, consider that if you edit one filter that the other one is still active so that you might use disableFilter() to switch it off.
Always use the given defines FILTER_x/ FILTER_EXT_x for the parameter num.
When disabling a filter for standard IDs use num: FILTER_x and set ext:0, if a filter for extended identifiers should be configured, then use num: FILTER_EXT_x and set ext:1.
Allowing all messages:
In order to let all messages be accepted again, just set two filters as follows. One (e.g. FILTER_0) for all standard IDs and another one for all extended IDs (e.g. FILTER_EXT_0):
init_FiltID(FILTER_0, 0, 0, MSG_ID_ALLOW_ALL_MASK);
init_FiltID(FILTER_EXT_0, 1, 0, MSG_ID_ALLOW_ALL_MASK);
Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN Bus ->
See also
Find more details about the CAN buses of dice devices
isFilterEnabled()
defines
init_FiltRang()
init_FiltID()
SAMC21_CAN – Library
CAN operation background
users manual
BOOTLOADER SETTINGS – Library
samc21 datasheet