Description
u8_set_can_listen_id()
allows you to configure the CAN ID (11 bit – standard ID) that the bootloader will be listening for at start-up. The bootloader expects to receive bootloader protocol messages with this CAN-ID. It is the CAN-ID that PC tools are using for communication to the target device [default 0x765].
Syntax
u8_set_can_listen_id( ou16_new_can_id );
Parameters
uint16_t ou16_new_can_id: the CAN ID of which we expect messages from the PC
Returns
uint8_t return value meaning:
0 – setting changed (accepted).
2 – the parameter ou16_new_can_id is out of range (0 … 0x7FF)
Example Code
This example shows how to read, set and store the ‘can listen id’ of the bootloader settings.
void setup()
{
Serial.begin();
while (!Serial)
{
yield(); // wait for PC CAN2SER-monitor to open
}
uint16_t u16_can_listen_id = BOOTLOADER_SETTING.u16_get_can_listen_id();
Serial.println("Current bootloader settings:");
Serial.println(" - can listen id: 0x"+ String( u16_can_listen_id, HEX ));
delay(2000);
Serial.println("Modify the settings");
BOOTLOADER_SETTING.u8_set_can_listen_id(0x765);
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
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.
It is recommended to leave the CAN Listen ID at its default value (0x765), because all tools and libraries use this ID by default. Change the can_listen_id ( = the send ID of the PC) only if it is really necessary. E.g. in case it is already used by another device on the same CAN bus.
See also
u8_store_bootloader_settings()
u16_get_can_listen_id()
SAMC21_CAN