cancel
Showing results for 
Search instead for 
Did you mean: 

X-NUCLEO-53L1A1 in MultiSensorRanging one interrupt per sensor

andreaspiezia9
Associate III

Hi all,

I'v modified the example of MultiSensorRanging in STM32CubeExpansion_53L1A1_V2.1.0.

I'v fitted JMP U11 and U18, and modified the file X-NUCLEO-53L1A1.h as indicated.

All sensors renging but only the centered generates interrups!

#ifndef VL53L1A1_GPIO1_SHARED
/**
 * @brief select use of shared interrupt
 *
 * Must be set to 0 (or not defined) for one interrupt per sensor
 * Must be set to non 0 for shared interrupt line
 * see @sa VL53L1A1_GPIO1_C_OPTION
 */
#   define VL53L1A1_GPIO1_SHARED  0
#endif
 
 /* X-NUCLEO-53L1A1.h */
#ifndef VL53L1A1_GPIO1_C_OPTION
/**
 * @def VL53L1A1_GPIO1_C_OPTION
 * @brief select GPIO1 to exti mapping for center or shared interrupt
 *
 * Set option value or un-define it to match with board configuration
 * @li not defined or 0  : U14=On  and U17=off  => GPIO1_C = PA4
 * @li defined and not 0 : U14=Off and U17=on  => GPIO1_C = PC1
 */
#   define VL53L1A1_GPIO1_C_OPTION 0
#endif
 
#ifndef VL53L1A1_GPIO1_L_OPTION
/**
 * @def VL53L1A1_GPIO1_L_OPTION
 * @brief control left sensor GPIO1 routing solder option
 * @warning not used on shared interrupt config
 *
 * Set option value or un-define it to match with board configuration
 * @li not defined or 0  : U10=on and  U11=Off => GPIO1_L = PC7
 * @li defined and not 0 : U10=off and U11=on  => GPIO1_L = PA9
 */
#   define VL53L1A1_GPIO1_L_OPTION 1
#endif
 
#ifndef VL53L1A1_GPIO1_R_OPTION
/**
 * @def VL53L1A1_GPIO1_R_OPTION
 * @brief control right sensor GPIO1 routing solder option
 * @warning not used on shared interrupt config
 *
 * Set option value or un-define it to match with board configuration
 * @li not defined or 0  : U18=on and  U15=Off => GPIO1_R = PA10
 * @li defined and not 0 : U18=off and U15=on  => GPIO1_R = PB5
 */
#   define VL53L1A1_GPIO1_R_OPTION 0
#endif
 /* END X-NUCLEO-53L1A1.h */
 
/* main.c */
	for (ToFSensor=0;ToFSensor<3;ToFSensor++){ //Reset the 3 ToF sensors on the expansion board
		status = XNUCLEO53L1A1_ResetId(ToFSensor, 0);
	}
 
	for (ToFSensor=0;ToFSensor<3;ToFSensor++){ // Bring the sensors out of the reset stage one by one and set the new I2C address
		switch(ToFSensor){
			case 0:
				Dev=&devLeft;
				break;
			case 1:
				Dev=&devCenter;
				break;
			case 2:
				Dev=&devRight;
				break;		
		}
		status = XNUCLEO53L1A1_ResetId(ToFSensor, 1);
		Dev->comms_speed_khz = 400;
		Dev->I2cHandle = &hi2c1;
		Dev->comms_type = 1;
		Dev->I2cDevAddr=0x52; // default ToF sensor I2C address
		VL53L1_RdWord(Dev, 0x010F, &wordData);
		printf("VL53L1X: %02X\n\r", wordData);
		newI2C = Dev->I2cDevAddr + (ToFSensor+1)*2;
		status = VL53L1_SetDeviceAddress(Dev, newI2C);
		Dev->I2cDevAddr=newI2C;
		VL53L1_RdWord(Dev, 0x010F, &wordData);
		printf("VL53L1X: %02X\n\r", wordData);
 
		status = VL53L1_WaitDeviceBooted(Dev);	// Device Initialization and setting
		status = VL53L1_DataInit(Dev);
		status = VL53L1_StaticInit(Dev);
		status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_SHORT);
		status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 300000);
		status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 1000);
 
	  	DetectionConf.DetectionMode = VL53L1_DETECTION_DISTANCE_ONLY;
	  	DetectionConf.IntrNoTarget = 0;
	  	DetectionConf.Distance.CrossMode = VL53L1_THRESHOLD_IN_WINDOW; //!< Trigger interrupt if value > thresh_low AND value < thresh_high
	  	DetectionConf.Distance.Low = 100; // in mm
	  	DetectionConf.Distance.High = 1000; //in mm
 
	  	//status = VL53L1_SetPresetMode(Dev, VL53L1_PRESETMODE_AUTONOMOUS);
 
		status = VL53L1_SetThresholdConfig(Dev, &DetectionConf);
		status = VL53L1_GetThresholdConfig(Dev, &DetectionConf);
		status = VL53L1_StartMeasurement(Dev);
		printf("Low: %d, High: %d, IntrNoTarget: %d, Mode: %d, CrossMode: %d\r\n", DetectionConf.Distance.Low, DetectionConf.Distance.High, DetectionConf.IntrNoTarget, DetectionConf.DetectionMode, DetectionConf.Distance.CrossMode );
 
	}

2 REPLIES 2
andreaspiezia9
Associate III

I've found the bug!

The GPIO9/10 must be set as GPIO4 (center sensor): i.e. PULLUP and IT_RISING:grinning_face_with_sweat:

  /*Configure GPIO pin : VL53L1X_INT_Pin */
  GPIO_InitStruct.Pin = VL53L1X_INT_Pin_Center|VL53L1X_INT_Pin_Left|VL53L1X_INT_Pin_Right;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(VL53L1X_INT_GPIO_Port, &GPIO_InitStruct);

John E KVAM
ST Employee

​Well done. I didn't know that. =)


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.