cancel
Showing results for 
Search instead for 
Did you mean: 

Moving from VL53L1CB to VL53L1X ULD API

nico23
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
nico23
Associate III

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

View solution in original post

2 REPLIES 2
John E KVAM
ST Employee

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. 


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
nico23
Associate III

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