cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 Disco - VL53L1X unable to communicate with sensor via API.

BDick.2
Associate II

I'm not an embedded Dev by any means, just trying to throw together a low energy project and I've been racking my head around this for a few weeks now, I can't get the STM32L0 to communicate with my VL53L1X via the provided API.

I'll post code snippets here shortly, but I've been able to communicate with it with the HAL read/write commands and do not get a HAL_ERROR (confirmed by altering device address and the HAL_ERROR was returned).

I'm able to run all of the API methods without getting an error status code but when I go to actually read the measurements it's negative, completely off (100s MM off) and it will always return the same measurement regardless of clear interrupt and start measurement.

If anyone has some insights into this let me know. I've ordered a logic analyzer to ensure that the API is actually doing anything with the sensor.

Also if anyone knows where I might be able to find any resources to using this sensor via HAL commands instead of the API that would be great. Only things I can seem to find online are forum posts here where people "figured it out".

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

What driver are you using, en.X-CUBE-53L1A1_v2.1.0 UltraLiteDriver? Are you using known-good hardware, e.g. a breadboard or bringing-up a new design?

View solution in original post

4 REPLIES 4
KnarfB
Principal III

What driver are you using, en.X-CUBE-53L1A1_v2.1.0 UltraLiteDriver? Are you using known-good hardware, e.g. a breadboard or bringing-up a new design?

Thanks for the response!

I'm using a breadboard and am able to use the sensor with a raspberry pi with the python drivers for the sensor so I know that the sensor, solders, and breadboard are all working properly.

I've been trying a lot of different ways of loading the API, following whatever tutorial/example looks promising.

When downloading that driver, am I just supposed to copy over the example project and change the `stm32xxx.h` imports to match the MCU I'm using?

BDick.2
Associate II

Here's my main() that I'm working with:

int main(void)
{
  /* USER CODE BEGIN 1 */
	uint8_t buff[50];
	VL53L1_RangingMeasurementData_t RangingMeasurementData;
	VL53L1_Dev_t  vl53l1; // center module
	VL53L1_DEV    Dev = &vl53l1;
	Dev->I2cHandle = &hi2c1;
	Dev->I2cDevAddr = (0x52);
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  /* USER CODE BEGIN 2 */
		__unused int status = 0;
	    uint8_t pData[4];
		HAL_StatusTypeDef hstatus;
		uint8_t modelId = 0xEA;
 
		// This returns HAL_OK.
		hstatus = HAL_I2C_Master_Transmit(&hi2c1, 0x52, &modelId, 1, 50);
		hstatus = HAL_I2C_Master_Receive(&hi2c1, 0x52, &pData, 4, 50);
 
 
		status = VL53L1_DataInit( Dev );
		status = VL53L1_StaticInit( Dev );
		status = VL53L1_SetDistanceMode( Dev, VL53L1_DISTANCEMODE_SHORT );
		status = VL53L1_SetMeasurementTimingBudgetMicroSeconds( Dev, 50000 );
		status = VL53L1_SetInterMeasurementPeriodMilliSeconds( Dev, 500 );
		status = VL53L1_StartMeasurement( Dev );
//	uint32_t Timeout = 50;
 
  //  status = VL53L1X_SetOffset(dev,20); /* offset compensation in mm */
  //  status = VL53L1X_SetROI(dev, 16, 16); /* minimum ROI 4,4 */
  //	status = VL53L1X_CalibrateOffset(dev, 140, &offset); /* may take few second to perform the offset cal*/
  //	status = VL53L1X_CalibrateXtalk(dev, 1000, &xtalk); /* may take few second to perform the xtalk cal */
//      status += VL53L1_StartMeasurement(Dev);   /* This function has to be called to enable the ranging */
 
      if (status) Error_Handler();
      int hold = 0;
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
	  status = VL53L1_WaitMeasurementDataReady(Dev);
	  status = VL53L1_GetRangingMeasurementData( Dev, &RangingMeasurementData );
	  status = VL53L1_ClearInterruptAndStartMeasurement( Dev );
	  if (RangingMeasurementData.RangeMilliMeter != hold) {
		  hold = RangingMeasurementData.RangeMilliMeter;
		  HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4); // driving an LED on the DISCO board.
		  HAL_Delay(500);
		  HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
	  }
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Hey @KnarfB​, I was able to get this finally reading by just copy+pasting the example of the ultralight driver and then the inc src directories into the cube ide project. Been one hell of a time trying to figure out where everything goes. Thanks for the help. Seems like my problem mostly stemmed from improper driver importing.