cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L0X_GetReferenceSpads() function retuns 0 as Spad count and PerformRefSpadManagement fails with Reference Spad Init Error. Why?

mgulsoy
Associate II

After static init in the code:

if(distOpStatus == VL53L0X_ERROR_NONE) {
		Print("Getting ReferenceSpads: ");
		distOpStatus = VL53L0X_GetReferenceSpads(pDistanceSensor, &refSpadCount, &isApertureSpads);
	}
 
	if(distOpStatus == VL53L0X_ERROR_NONE) {
		Print("Success! ");
		snprintf(TxBuffer, 64, "SPAD cnt: %lu,  isApartureSpads: %u\n", refSpadCount, isApertureSpads);
		Print(TxBuffer);
	}

the refSpadCount returns 0. Then:

if(distOpStatus == VL53L0X_ERROR_NONE) {
		Print("Setting up interrupt pin mode: ");
		distOpStatus = VL53L0X_SetGpioConfig(
				pDistanceSensor,
				0,
				VL53L0X_DEVICEMODE_SINGLE_RANGING,
				VL53L0X_GPIOFUNCTIONALITY_OFF, //off
				VL53L0X_INTERRUPTPOLARITY_HIGH
			);
	}
 
 
 
 
	if(distOpStatus == VL53L0X_ERROR_NONE)  {
		Print("success!\nPerforming RefSpadManagement: ");
		//SPAD : Single Photon Avalanche Diodes
		distOpStatus = VL53L0X_PerformRefSpadManagement(pDistanceSensor, &refSpadCount, &isApertureSpads);
	}

VL53L0X_PerformRefSpadManagement is failing with: Reference Spad Init Error (-50) .

By ignoring this error and trying to make single shot measurement fails always. What is wrong with my setup?

I am using Nucleo-G071RB with STM32CubeIDE (v1.1) with sensor breakout board from adafruit. I adapted the STSW-IMG005 using platform functions. I2c comm is working fine.

6 REPLIES 6
John E KVAM
ST Employee

I've seen this once before. It appears there was no default written into the non-volatile memory at the factory. (Or perhaps an incorrect one.)

Solution is to do a VL53L0X_SetReferenceSpad() prior to doing the Perform. By Setting a different number, it should work.

It's not obvious what values should be written but if you have a working sensor extract those values and use them.

Otherwise use some small number 3,0 should do it, I think.

  • john


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.
John E KVAM
ST Employee

Another approach is to edit out the error checks and get the device to run. I've been told the first few ranges will be bad. After that the sensor self corrects and runs successfully. Or just not do the RefSpad calibration and burn a dozen or so results.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question. It helps the next guy.

Hi John,

Thank you for your (1st) reply. Here is what I observe:

Only these values returned VL53L0X_ERROR_NONE from VL53L0X_SetReferenceSpads call (refSPADCount, isAperture):

  • (0,0)
  • (0,1) - (1,1) - (2,1) - (3,1) - (4,1) - (5,1) - (6,1) - (7,1)

I took 44 as max refSPADCount. So within the aperture and non-aperture values, only these values resulted without error.

If I do VL53L0X_StaticInit after VL53L0X_SetReferenceSpads, the VL53L0X_StaticInit call sets refSPADCount and isAperture values to: (0,0) always.

If I put VL53L0X_StaticInit before VL53L0X_SetReferenceSpads then refSPADCount and isAperture values is read as they are.

Whatever I do VL53L0X_PerformRefSpadManagement always returns -50 : Reference Spad Init Error.

However, if try to use DF-Robot arduino library, the sensor works with a 10 mm offset. When I look at the sensor with a cellphone cam, I can see the light emitted from the sensor. But no luck with the STSW-IMG005 library. I could not be able to see the light also with a cam. No methods are working as shown on examples.

Here is an example output of the firmware that I use:

0690X000009ZhXzQAK.jpg

We are designing a product based on the VL53L0X. We have invested a lot, and I would like to make the sensor work with the supplier supplied library not with a reverse-engineered one. Would you please help / assist me digging the reason?

Thank you in advance.

I will try that. When I get the results I will post them. Thank you for the answer.

pfontana96
Associate

Hi @Mert Gülsoy​ ,

I know this is a bit old but I'm facing the exact same problem you had. Were you able to solve it?

Thanks in advance

Hi @pfontana96​ 

Unfortunately we could not be able to solve the problem. Also the response times of the sensor are too high for our application so we have designed our own sensor. However, I have altered Pololu's library and made the sensor work. If you want I can send you the code. Send me a private message.