Description
setMode()
– starts the CAN bus in the selected operation mode MCP_NORMAL
or MCP_LISTENONLY
.
Syntax
MCAN1.setMode( operation_mode );
Parameters
uint8_t operation_mode – Selects the mode of operation MCP_NORMAL
or MCP_LISTENONLY
.
Returns
uint8_t:
CAN_OK – CAN mode of operation successfully started
CAN_FAIL – Error. CAN bus could not be started.
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(MCP_ANY, 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
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
begin()
defines
CAN operation background
users manual
BOOTLOADER SETTINGS – Library