Question
Issue with Operating Two VL53L5CX Sensors on the Same I2C Bus - Nucleo F401RE
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:
- I've successfully set up one sensor on I2C1 at address 0x52.
- I want to set up the second sensor on I2C1 at address 0x53 and attempt address changing.
- I've created two output pins (LPN1 and LPN2) for each sensor.
- Both sensors are connected to the same SDA and SCL lines of I2C1 using LPN1 and LPN2.
- I've managed to run one sensor at address 0x52 while setting LPN2 to 0 for the other sensor.
- I want to run the second sensor at address 0x53 (changing the address) while setting LPN1 to 0 for the other sensor.
- The address change should occur systematically at startup in the main function before the while loop.
- 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 */