Description
getFilterType( num, ext )
– returns the type that filter num
is configured.
Syntax
MCAN0.getFilterType( 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
uint8_t: CAN_FILTER_RANGE
– the filter is of type ID-range (configured with init_FiltID())
CAN_FILTER_CLASSIC
– the filter is of type ID / mask-ID (configured with init_FiltRang())
Example Code
The following example configures filters, checks them and receives messages on the CAN bus (MCAN0).
void setup()
{
while(!Serial);
Serial.println("Setting filters for CAN0");
// Set Single Standard ID filter (re-config FILTER_0)
MCAN0.init_FiltID(FILTER_0, 0 , 0x0A5);
// Disable the pre-configured FILTER_EXT_0 to not receive all msg. anymore
MCAN0.disableFilter(FILTER_EXT_0, 1);
Serial.print("Standard ID FILTER_0 is");
if( MCAN0.isFilterEnabled( FILTER_0, 0 ) )
Serial.print(" enabled and of type: ");
else
Serial.print(" disabled and of type: ");
if( MCAN0.getFilterType( FILTER_0, 0 ) == CAN_FILTER_RANGE)
Serial.println("ID range");
if( MCAN0.getFilterType( FILTER_0, 0 ) == CAN_FILTER_CLASSIC)
Serial.println("classic ID/Mask");
}
void loop()
{
// Receive CAN messages
if(MCAN0.checkReceive())
{
CANMessage t_canMesgToRecv;
if(MCAN0.readMsgBuf(t_canMesgToRecv) == CAN_OK)
Serial.println("CAN0: "+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 checking a filter for standard IDs use num: FILTER_x and set ext:0, if a filter for extended identifiers should be checked, 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
disableFilter()
defines
init_FiltRang()
init_FiltID()
SAMC21_CAN – Library
CAN operation background
users manual
BOOTLOADER SETTINGS – Library
samc21 datasheet