Description
CANMessage()
– the custrutor of the class CANMessage creates an instance of a CAN message.
Use this class for sending and receiving messages with the CAN bus MCAN0
/ MCAN1
.
Syntax
CANMessage myMsg;
Properties
uint32_t id
– 11 /29 bit identifier of the message
bool ext
– true: extended 29 bit identifier
uint8_t len
– DLC data length code – number of data bytes in the message
Data can be access through a ‘union‘ so either of the following would work:
uint8_t data[ ]
– data byte [0] . . . [7]
uint16_t data16[ ]
– data16[0] . . . [3]
uint32_t data32[ ]
– data[0] . . . [1]
uint64_t data64
toString()
The convenience function toString() creates a String holding the information of the CAN message
Example Code
The following example sends messages on CAN bus MCAN0 and prints received messages
void setup()
{
}
void loop ()
{
CANMessage myMsg;
myMsg.id = 0x12345;
myMsg.ext = true;
myMsg.len = 1;
myMsg.data[0] = 0xA5;
MCAN0.sendMsgBuf(myMsg);
if( MCAN0.checkReceive() )
{
CANMessage t_canMesgToRecv;
if(MCAN0.readMsgBuf(t_canMesgToRecv) == CAN_OK)
Serial.println( t_canMesgToRecv.toString() );
}
delay(100);
}
Notes and Warnings
Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN Bus ->
See also
Find more details about the ‘bootloader settings’ and the CAN bus of dice devices
SAMC21_CAN – Library
CAN operation background
users manual
BOOTLOADER SETTINGS – Library