UM2039 User Manual: World Smallest Time-of-Flight Ranging and Gesture Detection Sensor Application Programming Interface
UM2039 User Manual: World Smallest Time-of-Flight Ranging and Gesture Detection Sensor Application Programming Interface
User Manual
World smallest Time-of-Flight ranging and gesture detection sensor
Application Programming Interface
Introduction
VL53L0X is a ranging and gesture detection sensor.
The purpose of this User Manual is to describe the Application Programming Interface
(API), and the calibration procedures from a user perspective.
The API is a turnkey solution. It consists of a set of C functions which enables fast
development of end user applications, without the complication of direct multiple register
access. The API is structured in a way that it can be compiled on any kind of platform
through a well isolated platform layer.
The API package allows the user to take full benefit of VL53L0X capabilities
References
1. VL53L0X Datasheet (DS11555)
Contents
1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 System initialization/calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1 Data init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Static Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3 Load calibration data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.1 Reference SPADs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.2 Ref calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.3 Offset calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.4 Cross-talk correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.4 Device mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.5 Polling and interrupt mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Ranging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.1 Start a measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
9 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1 Overview
VL53L0X API is based on Photonic Abstraction Layer (PAL) specification. API is defined as
the implementation of the PAL.
The API exposes high level functions to be used by the customer application to control the
device.
Note: Full API documentation is available, as part of the API package, in chm and pdf formats.
There is an initial, once only, calibration step required that should be applied at customer
level during the manufacturing process. This flow takes into account all parameters (cover
glass, temperature & voltage) from the application.
The customer manufacturing calibration flow is described in Figure 2 below.
DataInit
Device
~40ms*
initialization
StaticInit
Calibration SPADs
data ~10ms*
calibration
Calibration Temperature
data ~40ms*
calibration
Offset
~300ms*
Calibration calibration
data
CrossTalk
~1sec*
Calibration calibration
data
Key
Calibration Calibration
data - Host Data result
The following sections detail the API function calls required to perform the initial system
calibration.
The cross-talk correction is basically a weighted gain applied to the ranging data, based on
a calibration result.
Correcting low cross-talk is easier than correcting high cross-talk.
This section describes the 3 phases that are required to perform the first range
measurement after reset, using the VL53L0X.
There are 3 phases:
• Initialization & load calibration data
• Ranging
• Digital housekeeping - see Section 6.2: Limit settings.
DataInit Device
~40ms*
initialization
StaticInit
Calibration
data
Calibration
Data Calibration data ~1ms*
loading
Calibration
data
Calibration
data
Additional or
Optional Settings
System settings ~1ms*
SetDeviceMode
SetGPIO
RANGING Key
Calibration
data - Host
12/26
Host action Host calls API
Data result API internal action
function
CONTINUOUS /
CONTINUOUS & TIMED SINGLE
SINGLE
Range profile phases
POLLING
NG INTERRUPT
INT
INTERRUPT
HOST / API
StartContinuous StartContinuous
API POLLING HOST POLLING
API POLLING
StartSingleRanging StartSingleMeas
HOST POLLING 1- StartSingleMeas
GetRangingMeasurementD 1- StartSingleMeas
2- WaitDataReady 2- WaitDataReady
ata (on Ranging Status)
GetRangingMeasurementD (on Ranging Status)
ata 3- GetValue
GetMeasuremenDataRead Interrupt received
Data
Data CONTINUE y
DocID029105 Rev 1
Data
CONTINUE GetRangingMeasu reme
GetRangingMeasu rementD HOST POLLING nData
Interrupt cleared
ata
Clear interrupt
GetRangingMeasu rementD
ata Data
Data
Data
End
GetRangingMeasu rementD
ata
GetStopCompletedStatus
Data
HOST POLLING
UM2039
UM2039 System initialization/calibration
4 System initialization/calibration
The following section shows the API function calls required to perform the system
initialization, before starting the first range measurement after reset.
5 Ranging
5.1.3 Start measurement, wait for data ready and report the data
VL53L0X_PerformSingleRangingMeasurement() function starts a measurement,
waits for data ready (by polling on the ranging status or on the interrupt status) and reports
the data. This function also clears the interrupt after the measurement.
The 3 following API functions are called internally:
• VL53L0X_PerformSingleMeasurement()
• VL53L0X_GetRangingMeasurementData()
• VL53L0X_ClearInterruptMask()
Note: SignalRateRtnMegaCps includes the crosstalk correction (if the correction is enabled). If the
user wants to get the signal rate without crosstalk correction, they can call
VL53L0X_GetTotalSignalRate() function.
Example of use:
Status = VL53L0X_SetLimitCheckEnable(pMyDevice,
VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
Status = VL53L0X_SetLimitCheckValue(pMyDevice,
VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 0.40*65536);
The current sigma value (the actual one, not the limit) can be accessed by calling:
Status = VL53L0X_GetLimitCheckCurrent(pMyDevice,
VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, &Sigma);
An API error code is reported when any API function is called. Possible values for API errors
are described in Table 4.
VL53L0X_GetPalErrorString() function returns the error string.
0 No Error - -
Calibration
-1 Not implemented, cannot happen N/A
warning error
-2 Min clipped error Not implemented, cannot happen N/A
-3 Undefined error Not implemented, cannot happen N/A
Invalid parameters Parameter passed is invalid or Wrong API programming (wrong setting used), or
-4
error out of range I2C transaction corrupted
Not supported Function is not supported in Wrong API programming (non implemented
-5
error current mode or configuration function called), or I2C transaction corrupted
Wrong API programming (syntax error), or no
Device reports a ranging error
-6 Range error target present during offset calibration, or I2C
interrupt status
transaction corrupted
Device is functionally failing, or I2C transaction
-7 Time out error Aborted due to time out
corrupted
Mode not Requested mode is not Wrong API programming (non existent mode
-8
supported error supported by the device called), or I2C transaction corrupted
-9 Buffer too small Cannot happen N/A
User tried to set up a non-existing Wrong API programming (wrong setting used), or
-10 GPIO not existing
GPIO pin I2C transaction corrupted
GPIO functionality Wrong API programming (wrong setting used), or
-11 Unsupported GPIO functionality
not supported I2C transaction corrupted
Control Interface Error reported from IO functions
-20 I2C comm error
Error (comm error)
Invalid Command
-30 Cannot happen N/A
Error
Division by zero
-40 Cannot occur in cut1.1 N/A
Error
Bad NVM programming, module aperture blocked
Reference SPAD Error during reference SPAD
-50 with high reflective target, I2C transaction
Init Error initialization
corrupted (wrong programming)
Not implemented
-99 Not implemented N/A
error
6.7 Reset
This functions resets the device and waits for the boot up.
VL53L0X_ResetDevice()
VL53L0X_SetInterruptThresholds()and
VL53L0X_GetInterruptThresholds()allow to set/get the interrupt thresholds.
After reading a measurement, host has to clear the interrupt by
using the following function.
VL53L0_ClearInterruptMask()
VL53L0X_ClearInterruptMask()and VL53L0X_GetInterruptMaskStatus()allow
to set/get the interrupt.
Example code is provided within the API release to help the implementation of interrupt
settings on the host.
Note: In Table 5, ranging mode all = continuous, continuous timed and single ranging
Note: There is no interrupt generated if no target is detected in threshold high mode (with any
threshold value).
if (Status == VL53L0_ERROR_NONE) {
Status = VL53L0_SetLimitCheckValue(pMyDevice,
VL53L0_CHECKENABLE_SIGMA_FINAL_RANGE,
(FixPoint1616_t)(60*65536));
}
if (Status == VL53L0_ERROR_NONE) {
Status =
VL53L0_SetMeasurementTimingBudgetMicroSeconds(pMyDevice,
33000);
}
if (Status == VL53L0_ERROR_NONE) {
Status = VL53L0_SetVcselPulsePeriod(pMyDevice,
VL53L0_VCSEL_PERIOD_PRE_RANGE, 18);
}
if (Status == VL53L0_ERROR_NONE) {
Status = VL53L0_SetVcselPulsePeriod(pMyDevice,
VL53L0_VCSEL_PERIOD_FINAL_RANGE, 14);
}
9 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.