Skip to main content
Associate
July 3, 2024
Solved

Multi tof sensors to one I2C bus

  • July 3, 2024
  • 2 replies
  • 1857 views

I am trying to connect two VL53L8CX time of flight sensors to STM32F401RET6. I need one I2C bus for both sensors but unable to assign slave address dynamically. I need to know where to modify the program in stm32cube IDE

Best answer by John E KVAM

Ah - There is a bug in the initial set of blue boards for the VL53L8 that makes causes a failure when connecting a satellite board. 

You can either wait until the new versions come out or you can have a look at:

an5945-how-to-connect-the-satelvl53l8-to-an-stm32-nucleo64-board-stmicroelectronics (2).pdf

This app note will show you how to connect 1 satellite board to your Nucleo. With a little soldering you can connect the second one. (I know I make it sound easier that it is - and it's somewhat messy as well.)

There is an App Note on this issue, but I'm having trouble finding it.

 

 

2 replies

John E KVAM
ST Employee
July 23, 2024

The trick is to have LPn low on one of your sensors. This way it's not paying attention to bus. Then issue the address change command to the one sensor that is paying attention. 

Create 2 'Dev' structures. I like an array of dev structures.

With one sensor in reset (LPn low) init the first sensor and change it's address. Then make sure you change the I2c address in the 'Dev[0]' structure. 

Then bring the LPn up on the second sensor and init as usual with Dev[1]. 

That should do it.

-john

Pooja18Author
Associate
July 24, 2024
 
 
  for(int i=0;i<2;i++)
  {
  if(i==0)
  {
  shut_sensor2();              // reset LPN pin of sensor2
  Resetsensor1();             // reset and set LPN  of sensor1
  Hardware_Init(&App_Config[i]);
  
  if ((vl53lmz_set_i2c_address(&(App_Config[i].ToFDev),0x62) < 0))
  {
printf("LMZ_platform_init failed\n");
Error_Handler();
  }
 
  /* Initialize the sensor */
  if (vl53lmz_init(&(App_Config[i].ToFDev)) != VL53LMZ_STATUS_OK)
  {
  printf("vl53lmz_init failed\n");
  Error_Handler();
  }
  }
  else if(i==1)
  {
  shut_sensor1();
  Resetsensor2();
  printf("Reset_done\n");
  Hardware_Init(&App_Config[i]);
  printf("Hardware_Init_done\n");
  Software_Init(&App_Config[i]);
  printf("Software_Init_done\n");
  }
}
  /* Infinite loop */
  while (1)
  {
 
  for(int i=0;i<2;i++)
  {
 
  Sensor_StartRanging(&App_Config[i]);
  printf("Sensor_StartRanging_done\n");
  delay();
      Sensor_GetRangingData(&App_Config[i],index_number,&sensor_out);
      delay();
 
  }
}
 
 
Here even after changing address and initializing both sensors individually, Start Ranging is not taking place. I want both sensors to range simultaneously. is it possible??
 
After initializing both sensors, controller is only communicating with last initialized sensor. In our case sensor with 0x62 is not communicating with controller

 

John E KVAM
ST Employee
July 24, 2024

yes it's possible. but in your code once you have configured the initial sensor to be 62 don't mess with its LPn line!

just bring the other sensor out of reset and initialize it. There will be no confusion. you will have one at 52 and one at 62.

it's that shut_sensor1(); that is killing you. it just reset the sensor you so carefully set up. 

And I'm not a fan of having a Sensor1 and a sensor2, when you access them with i=0 and i=1.

It's just me, but it reminds me fondly of my early Fortran days, before they invented arrays that started with 0. :)

- john 

Pooja18Author
Associate
July 25, 2024

I am actually using X-NUCLEO-53L8A1 expansion boards. Only one board can be Active at a time on the bus[power enable and LPN pins]. The second sensor will not be initialized without shutting the first one. We did try what you suggested but it did not work!!