VL53L0X API Status: -50 : Reference Spad Init Error (VL53L0X_1.0.2 hack)
That's not meant as a question, more as an input/feed-back for ST developers or users of the VL53L0X device.
I have a custom PCB with STM32F091 and two VL53L0X
Symptom:
If I initialize one only of the sensors, that sensor works great and gives good results.
No matter if it is the left or the right one.
If I initialize first one sensor, (changing device address while initializing)
then the other (also changing device address while initializing),
the second sensor while initializing always runs into
API Status: -50 : Reference Spad Init Error
My setup
custom PCB with STM32F091 + usual components on PCB TOP
2 VL53L0X devices 23cm apart on PCB Bottom.
STM32CubeIDE
Version: 1.4.2
Build: 7643_20200813_1322 (UTC)
VL53L0X_1.0.2 API from en.STSW-IMG005
slightly modified platform stuff in order to run on bare metal
Nucleo or discovery st-link to program the device
------------------------------------------------------------------------------------------------
I traced the error down to
vl53l0x_api_calibration.c
line 594
/* Confirm that the next good SPAD is non-aperture */
if (is_aperture(start + nextGoodSpad) != apertureSpads) {
/* if we can't get the required number of good aperture
* spads from the current quadrant then this is an error
*/
status = VL53L0X_ERROR_REF_SPAD_INIT;
break;
}this evalates to true if index in the enclosing for loop is
spadCount - 2
so I did the dirty hack
/* Confirm that the next good SPAD is non-aperture */
if (is_aperture(start + nextGoodSpad) != apertureSpads) {
/* if we can't get the required number of good aperture
* spads from the current quadrant then this is an error
*/
//FIXME crude hack to get pass second sensor the spad management
if (index < spadCount - 2) {
status = VL53L0X_ERROR_REF_SPAD_INIT;
break;
}
}and it seems to run OK.
------------------------------------------------------------------------------------------------------------------------------
here a console output with original code and the error occures
VL53L0 Test 00.01 from Nov 25 2020 at 08:52:15.
Hello Ju
>init_ToF for Device RIGHT
Ack on Adress : 0x29
>
call VL53L0X_DataInit
>API Status: 0 : No Error
Device RIGHT DataInit complete
>
call VL53L0X_DataInit
>API Status: 0 : No Error
Device RIGHT DataInit complete
>
call VL53L0X_SetDeviceAddress
>API Status: 0 : No Error
Device RIGHT VL53L0X_SetDeviceAddress complete
call VL53L0X_GetDeviceInfo
>Device Type : VL53L0X
Device ID : VL53L0CXV0DH/1$C
API Status: 0 : No Error
API Status: 0 : No Error
Call of VL53L0X_StaticInit
API Status: 0 : No Error
Call of VL53L0X_PerformRefCalibration
API Status: 0 : No Error
Call of VL53L0X_PerformRefSpadManagement
refSpadCount = 11, isApertureSpads = 0
API Status: 0 : No Error
Call of VL53L0X_SetDeviceMode
API Status: 0 : No Error
init_ToF for Device LEFT
Ack on Adress : 0x1E
Ack on Adress : 0x29
>
call VL53L0X_DataInit
>API Status: 0 : No Error
Device LEFT DataInit complete
>
call VL53L0X_SetDeviceAddress
>API Status: 0 : No Error
Device LEFT VL53L0X_SetDeviceAddress complete
call VL53L0X_GetDeviceInfo
>Device Type : VL53L0X
Device ID : VL53L0CXV0DH/1$C
API Status: 0 : No Error
API Status: 0 : No Error
Call of VL53L0X_StaticInit
API Status: -50 : Reference Spad Init Error
----------------------------------------------------------------------------------------------------------------
... and after the modification
VL53L0 Test 00.01 from Nov 25 2020 at 08:52:15.
Hello Ju
>init_ToF for Device RIGHT
Ack on Adress : 0x29
>
call VL53L0X_DataInit
>API Status: 0 : No Error
Device RIGHT DataInit complete
>
call VL53L0X_SetDeviceAddress
>API Status: 0 : No Error
Device RIGHT VL53L0X_SetDeviceAddress complete
call VL53L0X_GetDeviceInfo
>Device Type : VL53L0X
Device ID : VL53L0CXV0DH/1$C
API Status: 0 : No Error
API Status: 0 : No Error
Call of VL53L0X_StaticInit
API Status: 0 : No Error
Call of VL53L0X_PerformRefCalibration
API Status: 0 : No Error
Call of VL53L0X_PerformRefSpadManagement
refSpadCount = 11, isApertureSpads = 0
API Status: 0 : No Error
Call of VL53L0X_SetDeviceMode
API Status: 0 : No Error
init_ToF for Device LEFT
Ack on Adress : 0x1E
Ack on Adress : 0x29
>
call VL53L0X_DataInit
>API Status: 0 : No Error
Device LEFT DataInit complete
>
call VL53L0X_SetDeviceAddress
>API Status: 0 : No Error
Device LEFT VL53L0X_SetDeviceAddress complete
call VL53L0X_GetDeviceInfo
>Device Type : VL53L0X
Device ID : VL53L0CXV0DH/1$C
API Status: 0 : No Error
API Status: 0 : No Error
Call of VL53L0X_StaticInit
API Status: 0 : No Error
Call of VL53L0X_PerformRefCalibration
API Status: 0 : No Error
Call of VL53L0X_PerformRefSpadManagement
refSpadCount = 10, isApertureSpads = 0
API Status: 0 : No Error
Call of VL53L0X_SetDeviceMode
API Status: 0 : No Error
ready for ranging press 'r' for start/stop
--------------------------------------------------------------------------------------------------
first measured data while moving a white paper back and forth in front of the two sensors after code modification
API Status: 0 : No Error
ready for ranging press 'r' for start/stop
r
Sensor LEFT Ranging activated
Sensor RIGHT Ranging activated
>Call of VL53L0X_StartMeasurement
API Status: 0 : No Error
Call of VL53L0X_StartMeasurement
API Status: 0 : No Error
LEFT 128
RIGHT 130
RIGHT 139
RIGHT 128
RIGHT 141
RIGHT 128
RIGHT 142
RIGHT 128
RIGHT 128
LEFT 128
RIGHT 137
RIGHT 136
LEFT 133
LEFT 128
LEFT 132
RIGHT 133
RIGHT 129
RIGHT 152
LEFT 150
RIGHT 147
LEFT 148
RIGHT 145
LEFT 132
RIGHT 133
LEFT 128
RIGHT 40
LEFT 32
RIGHT 17
LEFT 10
RIGHT 16
RIGHT 0
LEFT 0
RIGHT 2
LEFT 4
RIGHT 4
LEFT 10
RIGHT 16
LEFT 20
RIGHT 18
LEFT 131
RIGHT 128
LEFT 134
RIGHT 128
LEFT 136
RIGHT 132
LEFT 128
Ranging Sensor LEFT deactivated
Ranging Sensor RIGHT deactivated
>Call of VL53L0X_StopMeasurement
Wait Stop to be completed
Stop completed Sensor LEFT
Call of VL53L0X_StopMeasurement
Wait Stop to be completed
Stop completed Sensor RIGHT
