2024-07-03 03:17 AM - last edited on 2024-07-23 08:40 AM by Amel NASRI
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
2024-07-23 10:02 AM
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
2024-07-23 10:21 PM
2024-07-24 07:56 AM
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