Description
begin()
– initialises the CAN hardware and sets the baud rate. The begin function can also be used to re-configure the CAN bus.
It is recommended to use this function for MCAN1
only. Use the bootloader settings library and/or the diceConfig tool to configure the baud rate of the main CAN bus (MCAN0
). After calling begin() it is necessary to call the setMode() function to start the CAN operations with the new baud rate and desired operation mode. begin() configures FILTER_0 (std.) and FILTER_EXT_0 (extended) to receive all messages.
Syntax
MCAN1.begin( ou32_baudrate );
Parameters
uint32_t ou32_baudrate – CAN bus baud-rate (e.g. 125000 for 125 kBaud)
Returns
uint8_t:
CAN_OK – CAN bus successfully initialised.
CAN_FAIL – Error. CAN bus instance is not linked to any available hardware resources.
Example Code
The following example initialises the second CAN bus MCAN1 (e.g. on a dice-2CAN device) to 1 MBaud and sends messages with extended ID.
void setup()
{
MCAN1.begin(1000 * 1000);
MCAN1.setMode(MCP_NORMAL);
}
void loop ()
{
CANMessage myMsg;
myMsg.id = 0x12345;
myMsg.ext = true;
myMsg.len = 1;
myMsg.data[0] = 0xA5;
MCAN1.sendMsgBuf(myMsg);
delay(100);
}
Notes and Warnings
Call setMode() after a calling begin() to start the CAN bus operations. The begin() function also configures the filters FILTER_0 and FILTER_EXT_0 to receive all messages.
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
setMode()
CAN operation background
users manual
BOOTLOADER SETTINGS – Library