This library allows to use the CAN bus(es) of dice devices which both provide the following features:

  • CAN 2.0 B, high-speed and low-speed, data rates up to 1 Mbps
  • Wakeup feature on both CAN buses on pattern according to ISO 11898-2
  • Listen only mode
  • DMA (direct memory access)
  • Hardware based message ID filtering
  • Standard and extended ID-, mask- and range-filters
  • RX – call-backs
  • CAN-FD ready*

To use this library

This library is included by the start-up code so that it is not necessary to include it in the application. The MCAN objects of the class SAMC21_CAN are also created at start-up so that the application can use them globally.:


MCAN1 is available for devices equipped with two CAN buses (e.g. dice-2CAN)
The first can-bus (MCAN0) is automatically initialized according to the bootloader-settings of the device. Both CAN-buses can subsequently also be (re-)initialised by the user application. Filters can be configured using init_FiltID() for single and mask filtering or init_FiltRang() for ID ranges. The default filter settings allow the reception of all messages (std. and extended).


void setup()
  Serial.println("Simple example receiving and 
                        sending CAN messages");

void loop()
  // Receive CAN messages
  if( MCAN0.checkReceive() )
    CANMessage t_canMesgToRecv;		
    if(MCAN0.readMsgBuf(t_canMesgToRecv) == CAN_OK)

  if(Serial.peek() != -1) // if the user hits enter
    CANMessage t_canMesgToSend; =  0x123;
    t_canMesgToSend.ext = false;
    t_canMesgToSend.len = 2;[0] = 0x01;[1] = 0x02;
    while(Serial.peek() != -1);


There are two way to receive messages. One uses the approach above while a second option creates C++ objects (SAMC21_CAN_RECEIVER) that are able to receive messages which are distributed by the background process.
The hardware is *CAN-FD ready, software support is pending

Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN Bus ->

SAMC21_CAN library compatibility

Further reads

Find more details about the ‘bootloader settings‘ and the CAN bus of dice devices
CAN operation background
Filter message IDs
users manual