2017-09-27 05:19 AM
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:
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-read2017-10-08 06:14 PM
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.