Skip to main content
Senior III
December 4, 2024
Solved

Moving from VL53L1CB to VL53L1X ULD API

  • December 4, 2024
  • 2 replies
  • 823 views

I'm using the full API for the VL53L1 ToF sensor. The project is pretty simple as I'm using 4 sensor to measure distance connected on an I2C of an STM32F091.

I'm optimizing the code and I'm come across the VL53L1X ULD API (Ultra Lite Driver Application Programming Interface) STSW-IMG009.

From what I'm seeing most of the function I'm using:

  • VL53L1_StartMeasurement
  • VL53L1_GetMeasurementDataReady
  • VL53L1_GetRangingMeasurementData
  • VL53L1_ClearInterruptAndStartMeasurement
  • XNUCLEO53L1A1_ResetId
  • VL53L1_SetDeviceAddress
  • VL53L1_WaitDeviceBooted
  • VL53L1_DataInit
  • VL53L1_StaticInit
  • VL53L1_SetDistanceMode
  • VL53L1_SetMeasurementTimingBudgetMicroSeconds
  • VL53L1_SetInterMeasurementPeriodMilliSeconds

Could be replaced with the ones available in the ULD API.

The only thing I can't understand is how to edit the Dev structure. I'm currently using

Dev->I2cHandle = &hi2c2;
Dev->comms_speed_khz = 100; //400
Dev->comms_type = 1;
Dev->I2cDevAddr = 0x52; // default ToF sensor I2C address

From what I'm understanding I have to edit VL51L1X_NVM_CONFIGURATION and VL51L1X_DEFAULT_CONFIGURATION with the settings I'm using.

Is that right?

Best answer by nico23

Ok I got it. Firstly I set up the I2C on the micro with

static void MX_I2C2_Init(void) {
 HAL_I2C_DeInit(&hi2c2);
 hi2c2.Instance = I2C2;
 ...

and then XNUCLEO53L1A1_Init() editing XNUCLEO53L1A1_I2C1Configure() with the config used in MX_I2C2_Init().

About the function I was using I switched them following like below:

  • VL53L1_StartMeasurement -> VL53L1X_StartRanging
  • VL53L1_GetMeasurementDataReady -> VL53L1X_CheckForDataReady
  • VL53L1_GetRangingMeasurementData -> VL53L1X_GetDistance and VL53L1X_GetRangeStatus
  • VL53L1_ClearInterruptAndStartMeasurement -> VL53L1X_ClearInterrupt
  • XNUCLEO53L1A1_ResetId -> same
  • VL53L1_SetDeviceAddress -> VL53L1X_SetI2CAddress
  • VL53L1_WaitDeviceBooted -> VL53L1X_BootState
  • VL53L1_DataInit -> VL53L1X_SensorInit
  • VL53L1_StaticInit -> VL53L1X_SensorInit
  • VL53L1_SetDistanceMode -> same
  • VL53L1_SetMeasurementTimingBudgetMicroSeconds -> VL53L1X_SetTimingBudgetInMs
  • VL53L1_SetInterMeasurementPeriodMilliSeconds -> VL53L1X_SetInterMeasurementInMs

2 replies

John E KVAM
ST Employee
December 4, 2024

When I set down the rules for the ULD driver, I specified absolute simplicity. No hiding of classes, no layers to hide behind, and dead simple code. 

Someone decided to eliminate all structures as well. INCLUDNG the 'dev' structure. 

Change that structure to an 'int'. Make the 'int' equal to the I2C address of your sensor. 

So uint16_t dev=0x52; by default, should do it. 

uint16_t dev=0x52;

But you should see an example of this.

Downloaded the latest from STSW-IMG009 - VL53L1X ULD API (Ultra Lite Driver Application Programming Interface) - STMicroelectronics

We are at version 3.5.4. 

nico23AuthorBest answer
Senior III
December 6, 2024

Ok I got it. Firstly I set up the I2C on the micro with

static void MX_I2C2_Init(void) {
 HAL_I2C_DeInit(&hi2c2);
 hi2c2.Instance = I2C2;
 ...

and then XNUCLEO53L1A1_Init() editing XNUCLEO53L1A1_I2C1Configure() with the config used in MX_I2C2_Init().

About the function I was using I switched them following like below:

  • VL53L1_StartMeasurement -> VL53L1X_StartRanging
  • VL53L1_GetMeasurementDataReady -> VL53L1X_CheckForDataReady
  • VL53L1_GetRangingMeasurementData -> VL53L1X_GetDistance and VL53L1X_GetRangeStatus
  • VL53L1_ClearInterruptAndStartMeasurement -> VL53L1X_ClearInterrupt
  • XNUCLEO53L1A1_ResetId -> same
  • VL53L1_SetDeviceAddress -> VL53L1X_SetI2CAddress
  • VL53L1_WaitDeviceBooted -> VL53L1X_BootState
  • VL53L1_DataInit -> VL53L1X_SensorInit
  • VL53L1_StaticInit -> VL53L1X_SensorInit
  • VL53L1_SetDistanceMode -> same
  • VL53L1_SetMeasurementTimingBudgetMicroSeconds -> VL53L1X_SetTimingBudgetInMs
  • VL53L1_SetInterMeasurementPeriodMilliSeconds -> VL53L1X_SetInterMeasurementInMs