cancel
Showing results for 
Search instead for 
Did you mean: 

Multi tof sensors to one I2C bus

Pooja18
Associate

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

3 REPLIES 3
John E KVAM
ST Employee

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


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'
Pooja18
Associate
 
 
  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

 

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 


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'