cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Operating Two VL53L5CX Sensors on the Same I2C Bus - Nucleo F401RE

rhamine
Associate

Sure! Here's the rephrased version of your request in English:

I'm using a Nucleo F401RE board with two VL53L5CX sensors. Here are the steps I've taken:

  1. I've successfully set up one sensor on I2C1 at address 0x52.
  2. I want to set up the second sensor on I2C1 at address 0x53 and attempt address changing.
  3. I've created two output pins (LPN1 and LPN2) for each sensor.
  4. Both sensors are connected to the same SDA and SCL lines of I2C1 using LPN1 and LPN2.
  5. I've managed to run one sensor at address 0x52 while setting LPN2 to 0 for the other sensor.
  6. I want to run the second sensor at address 0x53 (changing the address) while setting LPN1 to 0 for the other sensor.
  7. The address change should occur systematically at startup in the main function before the while loop.
  8. I want both sensors to work alternately, addressing either 0x52 or 0x53 in the while loop.

Everything works fine individually for each sensor, but when trying to run both sensors simultaneously, I encounter issues. I'm having trouble pinpointing the problem.

 

while (1) {
lpn1State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn_PORT, CUSTOM_VL53L5CX_LPn_PIN);
lpn2State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN);
    if (lpn1State == GPIO_PIN_SET && lpn2State == GPIO_PIN_SET) {
HAL_GPIO_WritePin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN, GPIO_PIN_RESET);
HAL_Delay(2);
    lpn1State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn_PORT, CUSTOM_VL53L5CX_LPn_PIN);
    lpn2State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN);
    printf("11\n");
    }else if (lpn1State == GPIO_PIN_SET && lpn2State == GPIO_PIN_RESET) {
        printf("10\n");
    MX_TOF1_Process();
HAL_GPIO_WritePin(CUSTOM_VL53L5CX_LPn_PORT, CUSTOM_VL53L5CX_LPn_PIN, GPIO_PIN_RESET);
HAL_Delay(2);
HAL_GPIO_WritePin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN, GPIO_PIN_SET);
HAL_Delay(2);
    lpn1State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn_PORT, CUSTOM_VL53L5CX_LPn_PIN);
    lpn2State = HAL_GPIO_ReadPin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN);
    }else if (lpn1State == GPIO_PIN_RESET && lpn2State == GPIO_PIN_SET) {
        printf("01\n");
        MX_TOF2_Process();
HAL_GPIO_WritePin(CUSTOM_VL53L5CX_LPn_PORT, CUSTOM_VL53L5CX_LPn_PIN, GPIO_PIN_SET);
HAL_Delay(2);
HAL_GPIO_WritePin(CUSTOM_VL53L5CX_LPn2_PORT, CUSTOM_VL53L5CX_LPn2_PIN, GPIO_PIN_RESET);
HAL_Delay(2);
    }else if (lpn1State == GPIO_PIN_RESET && lpn2State == GPIO_PIN_RESET) {
        printf("00\n");
    }
    /* USER CODE BEGIN 3 */
}
  /* USER CODE END 3 */
3 REPLIES 3

Please show a schematic of your setup - it's a far more effective way of communicating the setup than using words!

How are the VL53L5CX sensors mounted - a custom board? commercial breakout boards? other?

Some good, clear photos of your setup would help.

 


@rhamine wrote:

when trying to run both sensors simultaneously, I encounter issues. 


So what "issues", exactly, do you encounter?

 


@rhamine wrote:

 I'm having trouble pinpointing the problem.


What have you tried so far? What have you learned from that?

Have you looked at the I2C lines with an oscilloscope to see what's happening?

 

Please use this button to properly post source code:

AndrewNeil_0-1714038989141.png

 

 

rhamine_0-1714046483353.png

The issue is that both sensors operate individually on the same bus. I have initialized each sensor separately, and here is the output.

 

rhamine_1-1714046761167.png

 

static void MX_VL53L5CX_SimpleRanging_Process_TOF1(void)
{
uint32_t Id;
    if(!activate)
    {
printf("***Capteur 1 ARA*** \n");
    CUSTOM_RANGING_SENSOR_ReadID(CUSTOM_VL53L5CX, &Id);
CUSTOM_RANGING_SENSOR_GetCapabilities(CUSTOM_VL53L5CX, &Cap);
 
Profile.RangingProfile = RS_PROFILE_8x8_CONTINUOUS;
Profile.TimingBudget = TIMING_BUDGET; /* 5 ms < TimingBudget < 100 ms */
Profile.Frequency = RANGING_FREQUENCY; /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
Profile.EnableAmbient = 0; /* Enable: 1, Disable: 0 */
Profile.EnableSignal = 0; /* Enable: 1, Disable: 0 */
 
/* set the profile if different from default one */
CUSTOM_RANGING_SENSOR_ConfigProfile(CUSTOM_VL53L5CX, &Profile);
status = CUSTOM_RANGING_SENSOR_Start(CUSTOM_VL53L5CX, RS_MODE_BLOCKING_CONTINUOUS);
activate = true;
    }
status = CUSTOM_RANGING_SENSOR_GetDistance(CUSTOM_VL53L5CX, &Result);
print_result(&Result);
HAL_Delay(POLLING_PERIOD);
 
}
 
static void MX_VL53L5CX_SimpleRanging_Process_TOF2(void)
{
uint32_t Id2;
    if(!activate2)
    {
printf("***Capteur 2 ARA*** \n");
    CUSTOM_RANGING_SENSOR_ReadID(CUSTOM_VL53L5CX2, &Id2);
    CUSTOM_RANGING_SENSOR_GetCapabilities(CUSTOM_VL53L5CX2, &Cap2);
 
    Profile2.RangingProfile = RS_PROFILE_8x8_CONTINUOUS;
    Profile2.TimingBudget = TIMING_BUDGET; /* 5 ms < TimingBudget < 100 ms */
    Profile2.Frequency = RANGING_FREQUENCY; /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
    Profile2.EnableAmbient = 0; /* Enable: 1, Disable: 0 */
    Profile2.EnableSignal = 0; /* Enable: 1, Disable: 0 */
 
    CUSTOM_RANGING_SENSOR_ConfigProfile(CUSTOM_VL53L5CX2, &Profile2);
    status = CUSTOM_RANGING_SENSOR_Start(CUSTOM_VL53L5CX2, RS_MODE_BLOCKING_CONTINUOUS);
    activate2 = true;
 
    }
    status = CUSTOM_RANGING_SENSOR_GetDistance(CUSTOM_VL53L5CX2, &Result2);
    print_result2(&Result2);
    HAL_Delay(POLLING_PERIOD);
 
}

Please use this button to properly post source code:

AndrewNeil_0-1714052212255.png