Adding the VL53L1X Driver to an STM32Cube Project

i am using the irs11a ; 0J9776 . it looks like the pictures here: | VL53L1X Time-of-Flight Distance Sensor

i got the floats to work. just needed to set some build options.

i measured the pins. xshut, gpio and vdd are all on 2.8V

Ok great,

What happens if you change the I2C address from 0x41 to 0x52?

IT WORKS!! Thanks a ton!

but why doesnt the 52 show up in my address scan?

here is the code i use for address scan and it only outputs 41:

  /*-[ I2C Bus Scanning ]-*/
  uint8_t i = 0, ret;
  char text[100];
  for(int i=1; i<128; i++)
  {
      ret = HAL_I2C_IsDeviceReady(&hi2c2, (uint16_t)(i<<1), 3, 5);
      if (ret != HAL_OK) /* No ACK Received At That Address */
      {
    	  //sprintf(text, "no %d", i);
          //println(&huart1,text);
      }
      else if(ret == HAL_OK)
      {
    	  sprintf(text, "%d", i);
    	  println(&huart1,text);
      }
  }
  println(&huart1,"done");
  /*--[ Scanning Done ]--*/

Try this…

/*-[ I2C Bus Scanning ]-*/
  uint8_t i = 0, ret;
  char text[100];
  for(int i=1; i<128; i++)
  {
      ret = HAL_I2C_IsDeviceReady(&hi2c2, (uint16_t)(i<<1), 3, 5);
      if (ret != HAL_OK) /* No ACK Received At That Address */
      {
    	  //sprintf(text, "no %d", i);
          //println(&huart1,text);
      }
      else if(ret == HAL_OK)
      {
    	  sprintf(text, "%x", i << 1);
    	  println(&huart1,text);
      }
  }
  println(&huart1,"done");
  /*--[ Scanning Done ]--*/

WORKS! Thanks!

No problem!

Hello, I have a problem, I don’t have the X-NUCLEO-53L1A1 board, and I have connected the sensor pins to my stm32f103RB board, I have connected the IT pin to PC1 pin, the XSHUT to PC0, the gnd to gnd of the board, the VDD to 5V, and the SCL and SDA pins to a 47 kohm resistor and from there to the SCL and SDA pins on the board. I have copied the code from main and the results it shows me are: 255, -1, 65536.00, 65736.61

Welcome to the TechForum @davidtambor5! Ok, let’s break this down…

What board are you using?

I assume the board you’re using has a voltage regulator? Otherwise, this far exceeds the sensor’s rated voltage.

Just to be clear, you’re using two pull-up resistors right? One for each pin…

You copied the main() function from Listing 1 in the article? Since you’re not using the X-NUCLEO-53L1A1 shield, did you modify the project to utilize PC0 (XSHUT) directly instead of using GPIO expanders?

I have the VL53L1X-SATEL connected directly to STM32F103RB without the X-NUCLEO-53L1A1 expansion board. And I’m using two pull-up resistors, right

Great! I’ll try to replicate your issue. To which end of the satellite board are you making your connections?

Starting from the bottom left for the one with the interrupts to the PC1 pin, the one on its right for the SCL, the second from the bottom left, the XSHUT, for the PC0, the one next to it for SDA, the third one from the bottom to the left one for VDD and the one next to it for GND.
They would be as follows:
VDC GND
XSHUT SDA
INT SCL
And on the pins of the stm32f103 board:
5V GND
PC0 SDA
PC1 SCL

Hi @davidtambor5. Please try the following and see if it resolves your issue:

  1. Leave the INT pin disconnected. It is not used in this example.

  2. Configure PC0 as GPIO_Output and name it “XSHUT”

image

  1. Modify main() to manipulate XSHUT directly rather than through GPIO expanders
  /* USER CODE BEGIN 2 */

  // initialize vl53l1x communication parameters
  Dev->I2cHandle = &hi2c1;
  Dev->I2cDevAddr = 0x52;

  HAL_GPIO_WritePin(XSHUT_GPIO_Port, XSHUT_Pin, GPIO_PIN_RESET);
  HAL_Delay(2); // 2ms reset time
  HAL_GPIO_WritePin(XSHUT_GPIO_Port, XSHUT_Pin, GPIO_PIN_SET);
  HAL_Delay(2);

  /*** Initialize GPIO expanders ***//*
  // Unused GPIO should be configured as outputs to minimize the power consumption
  buff[0] = 0x14; // GPDR (GPIO set direction register)
  buff[1] = 0xFF; // GPIO_0 - GPIO_7
  buff[2] = 0xFF; // GPIO_8 - GPIO_15
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_1_ADDR, buff, 3, 0xFFFF );
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_2_ADDR, buff, 3, 0xFFFF );

  // clear XSHUT (disable center module) -> expander 1, GPIO_15
  buff[0] = 0x13; // GPSR + 1 ( GPIO set pin state register)
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_1_ADDR, buff, 1, 0xFFFF );
  HAL_I2C_Master_Receive( &hi2c1, EXPANDER_1_ADDR, buff, 1, 0xFFFF );
  buff[1] = buff[0] & ~( 1 << ( 15 - 8 ) ); // clear GPIO_15
  buff[0] = 0x13; // GPSR + 1 ( GPIO set pin state register)
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_1_ADDR, buff, 2, 0xFFFF );

  HAL_Delay( 2 ); // 2ms reset time

  // set XSHUT (enable center module) -> expander 1, GPIO_15
  buff[0] = 0x13; // GPSR + 1 ( GPIO set pin state)
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_1_ADDR, buff, 1, 0xFFFF );
  HAL_I2C_Master_Receive( &hi2c1, EXPANDER_1_ADDR, buff, 1, 0xFFFF );
  buff[1] = buff[0] | ( 1 << ( 15 - 8 ) ); // set GPIO_15
  buff[0] = 0x13; // GPSR + 1 ( GPIO set pin state register)
  HAL_I2C_Master_Transmit( &hi2c1, EXPANDER_1_ADDR, buff, 2, 0xFFFF );

  HAL_Delay( 2 );
*/
  /*** VL53L1X Initialization ***/
  VL53L1_WaitDeviceBooted( Dev );
  VL53L1_DataInit( Dev );
  VL53L1_StaticInit( Dev );
  VL53L1_SetDistanceMode( Dev, VL53L1_DISTANCEMODE_LONG );
  VL53L1_SetMeasurementTimingBudgetMicroSeconds( Dev, 50000 );
  VL53L1_SetInterMeasurementPeriodMilliSeconds( Dev, 500 );
  VL53L1_StartMeasurement( Dev );

  /* USER CODE END 2 */

ok, I’m going to try it

when compiling the program it keeps showing me the numbers: 255 -1 65536.00 65736.61. Do I just set it to GPIO_Output and rename it? Do I leave the rest as “NO PULL UP AND PULL DOWN”, etc?

Yes, just use the defaults.

image

Ok.
Well, what I said, the same thing keeps coming out hehehehe

Hmm. Well, these are the connections I am making and the application is working fine. Note that I am using 3.3V instead of 5V. If these match yours and you’re still having issues, you might want to message me some pictures of your setup so we can verify nothing is wrong there…

I think my error is hardware, because I have connected the SCL and SDA pins in series with the resistors and these resistors in series with the SCL and SDA pins on the board

That was what happened to me, now it works. Thank you so much

one last question, what do the ambient and signals variables show?