CAN (CANbus)

addFilter()

CAN::addFilter, addFilter, CAN.addFilter

Filter which messages will be added to the receive queue.

// SYNTAX
can.addFilter(id, mask);
can.addFilter(id, mask, type);

By default all messages are received. When filters are added, only messages matching the filters will be received. Others will be discarded.

Parameters:

  • id: the id pattern to match
  • mask: the mask pattern to match
  • type (optional): CAN_FILTER_STANDARD (default) or CAN_FILTER_EXTENDED

Returns: boolean true if the filter was added, false if there are too many filters (14 filters max).

// EXAMPLES
CANChannel can(CAN_D1_D2);
// Match only message ID 0x100
can.addFilter(0x100, 0x7FF);
// Match any message with the highest ID bit set
can.addFilter(0x400, 0x400);
// Match any message with the higest ID bit cleared
can.addFilter(0x0, 0x400);
// Match only messages with extended IDs
can.addFilter(0, 0, CAN_FILTER_EXTENDED);