cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L0X can't change I2C address

Fede Rico
Associate III
Posted on September 27, 2017 at 14:19

Hi there,

I have one VL53L0X ranging sensor that works fine with the ST library.

I performed the sensor configuration and I can read data form sensor.

Now I should add a second ranging sensor on the same I2C bus.

To change the address I perform this step:

  • Sensor power on. Set to high the XSHUT pin.
  • Change the address with the code below. The function returns VL53L0X_ERROR_NONE.
  • Initialise the sensor, using the new address --> This step fails.

This is the code to change the I2C address:

newAddr &= 0x7F;

if( VL53L0X_SetDeviceAddress(&RANGING_SENSOR_VL53L0X_Handler[idSensor].handler, newAddr * 2) == VL53L0X_ERROR_NONE )

{

/* Store the new 7-bit address */

RANGING_SENSOR_VL53L0X_Handler[idSensor].handler.I2cDevAddr = newAddr;

}

Is this the correct sequence to change the I2C address?

Why I cannot communicate with the sensor using the new address?

Thanks for the help!

Federico 

#i2c-address #vl53l0x #i2c-sensor-read
1 REPLY 1
Andrew Fletcher
Associate II
Posted on October 09, 2017 at 03:14

The following code works for me:

static const uint8_t i2cInitialAddress = 0x52; // LSB is reserved
uint8_t i2cFinalAddress = 0x60 + 2 * tofId;
VL53L0X_Dev_t* tofSens = &tofSensors_[tofId].handle_;
XSHUT_Control(tofId, GPIO_PIN_SET);
memset(tofSens, 0, sizeof(VL53L0X_Dev_t));
tofSens->I2cDevAddr = i2cInitialAddress;
tofSens->comms_type = 1;
tofSens->comms_speed_khz = 100;
VL53L0X_SetDeviceAddress(tofSens, i2cFinalAddress);
tofSens->I2cDevAddr = i2cFinalAddress;
VL53L0X_DataInit(tofSens) != VL53L0X_ERROR_NONE;
...�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I think the difference is I don't do the multiply by 2 for the set device address call.