Description
u8_set_listen_only()
allows to change the bootloader settings ‘listen only’, which controls the way the CAN bus (MCAN0
) will be initialised at systems start.
Syntax
u8_set_listen_only ( ob_listenOnlyMode );
Parameters
bool – ob_listenOnlyMode; when ‘true’ then this the device will initialise the first CAN bus (MCAN0
) at start-up in listen only mode. The CAN bus will not drive any dominate states in this state. If this setting is ‘false’ then the CAN bus will be started in normal operation mode. default value: false
Returns
uint8_t – 0: setting changed (accepted)
Example Code
This example shows how to set, read and store the ‘listen only’ value of the bootloader settings.
void setup()
{
Serial.begin();
while (!Serial)
{
yield(); // wait for PC CAN2SER-monitor to open
}
Serial.print(" - listen only: ");
if( BOOTLOADER_SETTING.u8_get_listen_only() )
Serial.print("YES");
else
Serial.print("NO");
delay(2000);
Serial.println("");
Serial.println("Modify the settings");
BOOTLOADER_SETTING.u8_set_listen_only(false);
delay(2000);
Serial.println("Store the settings in flash");
uint8_t u8_ret = BOOTLOADER_SETTING.u8_store_bootloader_settings();
if(u8_ret != 0)
Serial.println("Error writing into flash");
Serial.println("DONE");
}
void loop ()
{
}
Notes and Warnings
The listen only mode prevents the device to block the CAN bus in case of a wrong setting of the baud rate. However, remember that the CAN bus always needs at least two active nodes to establish communication. A CAN message remains on the bus until it is confirmed by at least one communication partner.
Don’t forget to call the function u8_store_bootloader_settings()
to write the changed settings into flash, so that the bootloader (and app.) has the new values at the next system start / reset.
See also
SAMC21_CAN
u8_get_listen_only()
u8_store_bootloader_settings()