Description
regReceiver()
– registers an object that is derived from the base class SAMC21_CAN_RECEIVER().
Syntax
MCAN0.regReceiver( &pt_receiverObj, u32_low_ID, u32_high_ID, ext);
Parameters
SAMC21_CAN_RECEIVER* pt_receiverObj – pointer to the SAMC21_CAN_RECEIVER object.
uint32_t u32_low_ID – begin of the CAN-ID range that pt_receiverObj should be notified about
uint32_t u32_high_ID– end of the CAN-ID range that pt_receiverObj should be notified about
uint8_t ext – CAN-IDs shall be of type extended (29bit) or standard (11bit)
Returns
bool:
true – The object could successfully be registered by the CAN bus object
false – The object could NOT be registered, there are no more slots left for new receiver instances.
Example Code
The following example sends messages on CAN bus MCAN0.
MY_ENGINE_CLASS myEngineObj; // create an instance of our class
void setup()
{
while(!Serial);
// register obj. with MCAN0 listening for std.IDs 0x123 & 0x124
MCAN0.regReceiver(&myEngineObj, 0x123, 0x124, 0);
}
void loop()
{
Serial.println("Engine temperature: "+String(myEngineObj.s8_Temperature));
Serial.println("Engine RPM: "+String(myEngineObj.u32_RPM));
delay(1000);
}
An example can be found in the Arduino IDE menu:File -> Examples -> DICE -> CAN_Bus -> ReceiverClassExample
Notes and Warnings
Each CAN bus object (MCAN0 / MCAN1) has up to 8 slot to handle SAMC21_CAN_RECEIVER() objects. Be aware that each CAN2SER and Datapool object is using one of those slots. So in an average application that uses Serial
and GPS
, there would be 6 slots available the application objects. Check the return value of regReceiver() to see if a slot could be assigned.
See also
SAMC21_CAN – Library
can_msg_recv_callback()
can_routine_callback()
deregReceiver()
CAN operation background
users manual
BOOTLOADER SETTINGS – Library