Question
Making a demo for VL53L3CX to manage different ToFs together using interrupt? I found MultiRangingSensor demo for VL53L1X and trying to modify it to work for VL53L3CX ,I have noticed that the code works for sensors sequentially!
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin==VL53L1X_INT_Pin)
{
IntCount++;
}
}
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t byteData;
uint16_t wordData;
uint8_t ToFSensor =1; // 0=Left, 1=Center(default), 2=Right
uint8_t newI2C = 0x52;
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
XNUCLEO53L3A2_Init();
/* USER CODE END 1 */
/* USER CODE BEGIN 2 */
/* Allow to select the sensor to be used, multi-sensor is not managed in this example.
Only when use use the Left ToF in interrupt mode, solder the U7 on the X-Nucleo-53L3A2 board
Only when use the Right ToF in interrupt mode, solder the U7 on the X-Nucleo-53L3A2 board
See "Solder drop configurations" in the X-Nucleo-53L3A2 User Manual for more details */
//ToFSensor = 1; // Select ToFSensor: 0=Left, 1=Center, 2=Right
for (ToFSensor=0;ToFSensor<3;ToFSensor++){
XNUCLEO53L3A2_ResetId(ToFSensor, 0); // Reset ToF sensor
}
for (ToFSensor=0;ToFSensor<3;ToFSensor++)
{
printf("VL53L1X Examples...\n");
switch(ToFSensor)
{
case 0:
Dev=&devLeft;
break;
case 1:
Dev=&devCenter;
break;
case 2:
Dev=&devRight;
break;
}
status=XNUCLEO53L3A2_ResetId(ToFSensor, 1);
Dev->comms_speed_khz = 400;
Dev->I2cHandle = &hi2c1;
Dev->comms_type = 1;
Dev->I2cDevAddr=0x52;
VL53LX_RdByte(Dev, 0x010F, &byteData);
printf("\n\rVL53LX Model_ID: %02X\n", byteData);
VL53LX_RdByte(Dev, 0x0110, &byteData);
printf("VL53LX Module_Type: %02X\n", byteData);
VL53LX_RdWord(Dev, 0x010F, &wordData);
printf("VL53LX: %02X\n\n", wordData);
//HAL_Delay(4);
newI2C = Dev->I2cDevAddr + (ToFSensor+1)*2;
status = VL53LX_SetDeviceAddress(Dev, newI2C);
Dev->I2cDevAddr=newI2C;
// VL53LX_RdWord(Dev, 0x010F, &wordData);
// printf("VL53LX: %02X\n\n", wordData);
/* Device Initialization and setting */
status = VL53LX_WaitDeviceBooted(Dev);
//printf("WaitDeviceBoot: %d \n", status);
status = VL53LX_DataInit(Dev);
//printf("DataInit: %d \n", status);
//status = VL53LX_SetDistanceMode(Dev, VL53LX_DISTANCEMODE_SHORT);
//printf("SetDistanceMode: %d \n", status);
status = VL53LX_SetMeasurementTimingBudgetMicroSeconds(Dev, 500000);
printf("SetMeasurementTimingBudge: %d \n", status);
status = VL53LX_StartMeasurement(Dev);
//printf("start measurement value: %d \n", status);
}
/* Sequential ranging loop */
while(1){
for (ToFSensor=0;ToFSensor<3;ToFSensor++){
switch(ToFSensor){
case 0:
Dev=&devLeft;
break;
case 1:
Dev=&devCenter;
break;
case 2:
Dev=&devRight;
break;
}
status = VL53LX_StartMeasurement(Dev);
status = VL53LX_WaitMeasurementDataReady(Dev);
if(!status)
{
status = VL53LX_GetMultiRangingData(Dev, pMultiRangingData);
if(status==0){
no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
//printf("Count=%5d, ", pMultiRangingData->StreamCount);
printf("#Objs=%1d ", no_of_object_found);
for(j=0;j<no_of_object_found;j++){
if(j!=0)printf("\n ");
printf("\n\r Dev_no%i, status=%d, D=%5dmm, Signal=%2.2f Mcps, Ambient=%2.2f Mcps\n",
ToFSensor,
pMultiRangingData->RangeData[j].RangeStatus,
pMultiRangingData->RangeData[j].RangeMilliMeter,
pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0,
pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0);
HAL_Delay(2);
}
//printf("\nDev_no%i,distance = %5d \n",ToFSensor, pMultiRangingData->RangeData[0].RangeMilliMeter);
}
status = VL53LX_ClearInterruptAndStartMeasurement(Dev);
}
}
}
//RangingLoop();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
//while (1)
// {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//}
/* USER CODE END 3 */
}
-------------
/* ranging and display loop */
void RangingLoop(void)
{
// uint8_t NewDataReady=0;
int no_of_object_found=0,j;
printf("Ranging loop starts\n");
status = VL53LX_WaitDeviceBooted(Dev);
//printf("WaitDeviceBoot: %d \n", status);
status = VL53LX_DataInit(Dev);
//printf("DataInit: %d \n", status);
status = VL53LX_SetDistanceMode(Dev, VL53LX_DISTANCEMODE_SHORT);
//printf("SetDistanceMode: %d \n", status);
status = VL53LX_SetMeasurementTimingBudgetMicroSeconds(Dev, 500000);
// printf("SetMeasurementTimingBudge: %d \n", status);
status = VL53LX_StartMeasurement(Dev);
//printf("start measurement value: %d \n", status);
if(status){
printf("VL53LX_StartMeasurement failed: error = %d \n", status);
while(1);
}
if (isInterrupt){
do // HW interrupt mode
{
__WFI();
if(IntCount !=0 ){
IntCount=0;
status = VL53LX_GetMultiRangingData(Dev, pMultiRangingData);
if(status==0){
no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
printf("Count=%5d, ", pMultiRangingData->StreamCount);
printf("#Objs=%1d ", no_of_object_found);
for(j=0;j<no_of_object_found;j++){
if(j!=0)printf("\n ");
printf("status=%d, D=%5dmm, Signal=%2.2f Mcps, Ambient=%2.2f Mcps",
pMultiRangingData->RangeData[j].RangeStatus,
pMultiRangingData->RangeData[j].RangeMilliMeter,
pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0,
pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0);
}
printf ("\n");
status = VL53LX_ClearInterruptAndStartMeasurement(Dev);
}
else{
printf("VL53LX_GetMultiRangingData failed: error = %d \n", status);
while(1);
}
}
}
while(1);
}
}By executing this code and using TeraTerm I can see the ranges and all but still It doesn't not even entering the RangingLoop not through Interrupt or Polling so I would like to know what could be the problem...Thanks in advance
