Description

u8_set_local_id() allows you to configure the LID (local ID) of the device. CAN messages with this local ID are addressed to this device. The LID is required to be used uniquely by only one device at the same CAN bus. By default the value is 1. If more than one dice device is connected to the CAN bus then one of which has to get a different LID (e.g. 2). The LID is coded into the first data byte of CAN messages following the bootloader and CAN2SER protocol. -> Device addressing

Syntax

u8_set_local_id( ou8_new_local_id );

Parameters

uint8_t ou8_new_local_id: the new LID of the device (range: 1 … 62, default: 1)

Returns

uint8_t return value meaning:
0 – setting changed (accepted).
2 – the parameter ou8_new_local_id is out of range (1 … 62)

Example Code

This example shows how to read, set and store the ‘local id’ of the bootloader settings.

void setup()
{  
  Serial.begin();
  while (!Serial) 
  {
    yield(); // wait for PC CAN2SER-monitor to open 
  }
  uint8_t u8_local_id = BOOTLOADER_SETTING.u8_get_local_id();
  
  Serial.println("Current bootloader settings:");
  Serial.println(" - own local id : "+ String( u8_local_id));
  
  delay(2000);
  Serial.println("Modify the settings");
  BOOTLOADER_SETTING.u8_set_local_id(1);
  
  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 LID (local id) of the device at its default value (1), because all tools and libraries use this LID by default. Change the LID ( = our address on the bus) only if it is really necessary. E.g. in case there are more than one dice device on the same CAN bus.

See also

u8_store_bootloader_settings()
u8_get_local_id()
CAN2SER