Skip to main content
Associate III
July 10, 2026
Solved

Question about refSpadCount value of VL53L0x

  • July 10, 2026
  • 6 replies
  • 86 views

Hi  ,

   he system operates in timing mode with lower limit detection at 1.1-second intervals and a measurement duration of 33 ms; the status code is read to verify accuracy, though misjudgments may occur—for instance, when no object is present, measured values may fall below the lower limit, requiring correction. Parameters: long-distance reference Spad count = 7; aperture Spads = 1; HV settings = 32; Phase calibration = 1; Offset micrometer = 7000 (for 100 mm); myXTalk compensation rate (Mega CPS) = 66 (for 600 mm).
Why is the refSpadCount value obtained by our school less than 10?
Increasing the measurement time reduces the likelihood of misjudgment, as I use a battery-powered device and cannot extend the measurement duration.

Best answer by zhy

  do

    {

        Status |= vl53l0x_init(&vl53l0x_dev);                         //VL53L0X_DataInit()

        Status |= VL53L0X_StaticInit(&vl53l0x_dev);  

        // Status |= VL53L0X_SetDeviceMode(&vl53l0x_dev,VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING);

        GPIOB_InverseBits(OBJ_LED);

        mDelayuS(500);

    }while(Status != VL53L0X_ERROR_NONE);                            //如果TOF有问题或接触不良,LED会以2Hz频率闪烁

while(1)

{

    Status = VL53L0X_ERROR_NONE;

    KEY_SCAN();

    if(KEY3_PRESS_flag)                //RST键(要改造)  不需要?特定的光照条件。室内正常光线即可,校准期间,确保传感器前方 ?1 米内无遮挡物?,或者至少保持开阔空间

    {//第一步

        GPIOB_SetBits(OBJ_LED);;        //让LED灭,不影响标定

        KEY3_PRESS_flag = 0;

        VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);  //初始值myrefSpadCount_readout=5,myisApertureSpads_readout =0

        mDelayuS(20);

 

        Status = VL53L0X_PerformRefSpadManagement(&vl53l0x_dev,&myrefSpadCount,&myisApertureSpads);  //执行参考Spad管理 refSpadCount = 8;isApertureSpads= 1

        if(Status == VL53L0X_ERROR_NONE)

        {

            VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);  //执行Spad校准后 refSpadCount = 8;isApertureSpads= 1

             

            Write_eeprom(refSpadCount_addr,&myrefSpadCount,sizeof(myrefSpadCount));

            Write_eeprom(isApertureSpads_addr,&myisApertureSpads,sizeof(myisApertureSpads));

            Read_eeprom(refSpadCount_addr,&myrefSpadCount_readout,sizeof(myrefSpadCount_readout));

            Read_eeprom(isApertureSpads_addr,&myisApertureSpads_readout,sizeof(myisApertureSpads_readout));

            if((myrefSpadCount != myrefSpadCount_readout) && (myisApertureSpads_readout != myisApertureSpads ) )  

            {

               goto ERR1;  

            }

        }

        else

        {

            goto ERR1;                                       //让LED灭,表示标定不成功

        }

        //Status |= VL53L0X_StaticInit(&vl53l0x_dev);    

        Status |= VL53L0X_PerformRefCalibration(&vl53l0x_dev, &myVhvSettings, &myPhaseCal);//Ref参考校准   (如果中断充许,则会产生中断,中断会被清除)

 

        if(Status == VL53L0X_ERROR_NONE)

        {

            VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);

            Write_eeprom(VhvSettings_addr,&myVhvSettings,sizeof(myVhvSettings));

            Read_eeprom(VhvSettings_addr,&myVhvSetting_readout,sizeof(myVhvSetting_readout));

            if(myVhvSettings != myVhvSetting_readout) goto ERR1;

            Write_eeprom(PhaseCal_addr,&myPhaseCal,sizeof(myPhaseCal));

            Read_eeprom(PhaseCal_addr,&myPhaseCal_readout,sizeof(myPhaseCal_readout));

            if(myPhaseCal == myPhaseCal_readout)    

                GPIOB_ResetBits(OBJ_LED);                         //让LED亮

            else  

                goto ERR1 ;

        }

        else  

        {

ERR1:       GPIOB_SetBits(OBJ_LED);                           //让LED灭,表示标定不成功

        }

    }

    else if(KEY2_PRESS_flag)     //Download键  做offset键                            

    {//第二步 暗环境 100mm    

        GPIOB_SetBits(OBJ_LED);;                               //让LED灭,不影响标定

        KEY2_PRESS_flag = 0 ;

        mDelayuS(20);

        Status |= VL53L0X_PerformOffsetCalibration(&vl53l0x_dev,myCalDistanceMilliMeter,&myOffsetMicroMeter);//长距离  

        if(Status == VL53L0X_ERROR_NONE)

        {

            Write_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter,sizeof(myOffsetMicroMeter));    //把标定的结果写入EEPROM

            Read_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter_readout,sizeof(myOffsetMicroMeter_readout));    

            if(myOffsetMicroMeter == myOffsetMicroMeter_readout)    

               GPIOB_ResetBits(OBJ_LED);                          //让LED亮

            else

               goto ERR2;

        }

        else

        {

ERR2:       GPIOB_SetBits(OBJ_LED);;                          //让LED灭,表示标定不成功

        }

    }

    //串扰校准-----------------------------------------------------

 

    else if(KEY1_PRESS_flag)       //KEY键  做XTALK

    {//第三步 600mm 最好暗环境

        GPIOB_SetBits(OBJ_LED);;                               //让LED灭,不影响标定

        KEY1_PRESS_flag = 0;

        mDelayuS(20);                                        

        Status |= VL53L0X_PerformXTalkCalibration(&vl53l0x_dev,(600<<16),&myXTalkCompensationRateMegaCps);    //现是600mm,我知道要以实际实际测距拐点为准,但一般为450--600mm

        if(Status == VL53L0X_ERROR_NONE)

        {

            Write_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps,sizeof(myXTalkCompensationRateMegaCps));  

            Read_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps_readout,sizeof(myXTalkCompensationRateMegaCps_readout));

            if(myXTalkCompensationRateMegaCps == myXTalkCompensationRateMegaCps_readout)  

               GPIOB_ResetBits(OBJ_LED);                          //让LED亮

            else  

            {

               goto ERR3;

            }

             

        }

        else

        {

ERR3:       GPIOB_SetBits(OBJ_LED);;                          //让LED灭,表示标定不成功

        }

    }

6 replies

zhyAuthorBest answer
Associate III
July 10, 2026

  do

    {

        Status |= vl53l0x_init(&vl53l0x_dev);                         //VL53L0X_DataInit()

        Status |= VL53L0X_StaticInit(&vl53l0x_dev);  

        // Status |= VL53L0X_SetDeviceMode(&vl53l0x_dev,VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING);

        GPIOB_InverseBits(OBJ_LED);

        mDelayuS(500);

    }while(Status != VL53L0X_ERROR_NONE);                            //如果TOF有问题或接触不良,LED会以2Hz频率闪烁

while(1)

{

    Status = VL53L0X_ERROR_NONE;

    KEY_SCAN();

    if(KEY3_PRESS_flag)                //RST键(要改造)  不需要?特定的光照条件。室内正常光线即可,校准期间,确保传感器前方 ?1 米内无遮挡物?,或者至少保持开阔空间

    {//第一步

        GPIOB_SetBits(OBJ_LED);;        //让LED灭,不影响标定

        KEY3_PRESS_flag = 0;

        VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);  //初始值myrefSpadCount_readout=5,myisApertureSpads_readout =0

        mDelayuS(20);

 

        Status = VL53L0X_PerformRefSpadManagement(&vl53l0x_dev,&myrefSpadCount,&myisApertureSpads);  //执行参考Spad管理 refSpadCount = 8;isApertureSpads= 1

        if(Status == VL53L0X_ERROR_NONE)

        {

            VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);  //执行Spad校准后 refSpadCount = 8;isApertureSpads= 1

             

            Write_eeprom(refSpadCount_addr,&myrefSpadCount,sizeof(myrefSpadCount));

            Write_eeprom(isApertureSpads_addr,&myisApertureSpads,sizeof(myisApertureSpads));

            Read_eeprom(refSpadCount_addr,&myrefSpadCount_readout,sizeof(myrefSpadCount_readout));

            Read_eeprom(isApertureSpads_addr,&myisApertureSpads_readout,sizeof(myisApertureSpads_readout));

            if((myrefSpadCount != myrefSpadCount_readout) && (myisApertureSpads_readout != myisApertureSpads ) )  

            {

               goto ERR1;  

            }

        }

        else

        {

            goto ERR1;                                       //让LED灭,表示标定不成功

        }

        //Status |= VL53L0X_StaticInit(&vl53l0x_dev);    

        Status |= VL53L0X_PerformRefCalibration(&vl53l0x_dev, &myVhvSettings, &myPhaseCal);//Ref参考校准   (如果中断充许,则会产生中断,中断会被清除)

 

        if(Status == VL53L0X_ERROR_NONE)

        {

            VL53L0X_GetReferenceSpads(&vl53l0x_dev,&myrefSpadCount_readout,&myisApertureSpads_readout);

            Write_eeprom(VhvSettings_addr,&myVhvSettings,sizeof(myVhvSettings));

            Read_eeprom(VhvSettings_addr,&myVhvSetting_readout,sizeof(myVhvSetting_readout));

            if(myVhvSettings != myVhvSetting_readout) goto ERR1;

            Write_eeprom(PhaseCal_addr,&myPhaseCal,sizeof(myPhaseCal));

            Read_eeprom(PhaseCal_addr,&myPhaseCal_readout,sizeof(myPhaseCal_readout));

            if(myPhaseCal == myPhaseCal_readout)    

                GPIOB_ResetBits(OBJ_LED);                         //让LED亮

            else  

                goto ERR1 ;

        }

        else  

        {

ERR1:       GPIOB_SetBits(OBJ_LED);                           //让LED灭,表示标定不成功

        }

    }

    else if(KEY2_PRESS_flag)     //Download键  做offset键                            

    {//第二步 暗环境 100mm    

        GPIOB_SetBits(OBJ_LED);;                               //让LED灭,不影响标定

        KEY2_PRESS_flag = 0 ;

        mDelayuS(20);

        Status |= VL53L0X_PerformOffsetCalibration(&vl53l0x_dev,myCalDistanceMilliMeter,&myOffsetMicroMeter);//长距离  

        if(Status == VL53L0X_ERROR_NONE)

        {

            Write_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter,sizeof(myOffsetMicroMeter));    //把标定的结果写入EEPROM

            Read_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter_readout,sizeof(myOffsetMicroMeter_readout));    

            if(myOffsetMicroMeter == myOffsetMicroMeter_readout)    

               GPIOB_ResetBits(OBJ_LED);                          //让LED亮

            else

               goto ERR2;

        }

        else

        {

ERR2:       GPIOB_SetBits(OBJ_LED);;                          //让LED灭,表示标定不成功

        }

    }

    //串扰校准-----------------------------------------------------

 

    else if(KEY1_PRESS_flag)       //KEY键  做XTALK

    {//第三步 600mm 最好暗环境

        GPIOB_SetBits(OBJ_LED);;                               //让LED灭,不影响标定

        KEY1_PRESS_flag = 0;

        mDelayuS(20);                                        

        Status |= VL53L0X_PerformXTalkCalibration(&vl53l0x_dev,(600<<16),&myXTalkCompensationRateMegaCps);    //现是600mm,我知道要以实际实际测距拐点为准,但一般为450--600mm

        if(Status == VL53L0X_ERROR_NONE)

        {

            Write_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps,sizeof(myXTalkCompensationRateMegaCps));  

            Read_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps_readout,sizeof(myXTalkCompensationRateMegaCps_readout));

            if(myXTalkCompensationRateMegaCps == myXTalkCompensationRateMegaCps_readout)  

               GPIOB_ResetBits(OBJ_LED);                          //让LED亮

            else  

            {

               goto ERR3;

            }

             

        }

        else

        {

ERR3:       GPIOB_SetBits(OBJ_LED);;                          //让LED灭,表示标定不成功

        }

    }

ST Technical Moderator
July 13, 2026

Hi:

This code is for the three-step calibration process of VL53L0X: 
1.KEY3: Reference SPAD/Ref calibration (Normal indoor environment, unobstructed)
2.KEY2: Offset calibration (Specific distance, specific target, weak ambient light)
3.KEY1: XTalk calibration (Dark environment, uniform target, specified distance)
Then write the results into EEPROM for subsequent recovery and compensation, which is a typical VL53L0X productized calibration scheme. 

Based on my understanding, the refSpadCount value < 10 is right. 

Best regards,

Bin FAN

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.
zhyAuthor
Associate III
July 14, 2026

Dear  Bin :

      When there are no obstacles ahead, abnormal values may sometimes be displayed, as shown below,Why is the value of SignalRateRtnMegaCps so high when there's nothing ahead? 

 

zhyAuthor
Associate III
July 14, 2026

Dear  Bin

What do Signal Rate Return Mega Cps, Ambient Rate Return Mega Cps, Effective Spad Return Count mean? What are their ranges? The data we're currently receiving shows refSpadCount = 8.
signalLimit = 0.8 × 65536; sigmaLimit = 40 × 65536; timingBudget = 3300; preRangeVcselPeriod = 18; finalRangeVcselPeriod = 14. I used continuous timing mode with an interval of 1 second.

ST Technical Moderator
July 17, 2026

Hi:

SignalRateRtnMegaCps: this value is the return signal rate in MegaCountPer Second (MCPS). The signal value returned by the target object.

AmbientRateRtnMegaCps: this value is the return ambient rate (in MCPS). The intensity of the background ambient light

EffectiveSpadRtnCount: this is a16-bit integer that returns the effective SPAD count for the current ranging. 

Normally:

the blue part means refSpad.

The number of SPADs is calibrated during the final module test at ST. This part-to-part value is stored into the NVM and automatically loaded into the device during bootup.

This calibration allows the number of SPADs to optimize the device dynamic to be adjusted.

However, adding a cover glass on top of the module may affect this calibration. ST recommends that the customer performs this calibration again in the final product application.

 

The green part means return SPAD (EffectiveSpadRtnCount : The actual number of SPADs involved in effective measurement in distance measurement)

 

Best regards,

Bin FAN

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.
zhyAuthor
Associate III
July 14, 2026

Dear Bin 

  How should I determine the XTALK calibration distance: using the factory-default RefPAD and offset values, or the calibration data obtained after applying the cover plate? If using the calibration data with the cover plate applied, should I set the XTALK value to 0 before confirmation?

 

zhyAuthor
Associate III
July 14, 2026

Dear Bin 

Should the second argument of the function be shifted left by 16 bits for the XTALK correction distance?

 

ST Technical Moderator
July 17, 2026

Hi,

VL53L0X API User_Manual.fm

According to UM2039, the XTALK calibration distance should be determined with the final optical setup in place, meaning after the cover plate / cover window is mounted.

The recommended calibration flow is:

  1. DataInit
  2. StaticInit
  3. Reference SPAD calibration (refSpadCount)
  4. Ref calibration (VHV and phase cal)
  5. Offset calibration
  6. XTALK calibration

So in practice, you should not choose the XTALK calibration distance only from the factory-default bare-module condition. It should be based on the ranging behavior of the final system with the cover plate installed.

Regarding your second question:
there is no need to manually set the XTALK value to 0 as a mandatory API step before running VL53L0X_PerformXTalkCalibration(). However, it is better to start from a clean initialization state and avoid re-running XTALK calibration while an old XTALK correction is already loaded and active.

For the calibration distance itself, UM2039 says that the valid XTALK calibration region is where the measured curve starts to deviate from the ideal one, but before the return signal becomes too weak. The manual also recommends using:

  • 17% grey target
  • at least 600 mm
  • covering the full FoV

And for your last point:
the second argument of VL53L0X_PerformXTalkCalibration() is in millimeters, so it should be passed directly as, for example:

VL53L0X_PerformXTalkCalibration(&vl53l0x_dev, 400, &myXTalkCompensationRateMegaCps);

It should not be shifted left by 16 bits.

Best regards,

Bin FAN

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.
zhyAuthor
Associate III
July 20, 2026

Hi dear BIN

    but   

     the distance is FixPoint1616_t

 

ST Technical Moderator
July 20, 2026

Hi:

you can use hexadecimal as input parameter. For example, if you want to set 2.75.

2.75×65536=180224 = 0x0002C000

Best regards,

Bin FAN

 

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.
zhyAuthor
Associate III
July 20, 2026

not sucess. 

zhyAuthor
Associate III
July 20, 2026

Dear Bin

   

void vl53l0x_interrupt_start(VL53L0X_Dev_t *dev,uint8_t mode)

{

     uint8_t VhvSettings;

     uint8_t PhaseCal;

     uint32_t refSpadCount;

     uint8_t isApertureSpads;

     

     VL53L0X_Error status=VL53L0X_ERROR_NONE;//工作状态

       

    if(vl53l0x_init(dev))            //vl53l0x初始化  VL53L0X_DataInit()  

    {

        // printf("VL53L0X_Init Error!!!\r\n");

        mDelayuS(200);

    }

    else

        // printf("VL53L0X_Init OK\r\n");

   

   

     vl53l0x_reset(dev);//复位vl53l0x(频繁切换工作模式容易导致采集距离数据不准,需加上这一代码)

     status = VL53L0X_StaticInit(dev);

     if(status!=VL53L0X_ERROR_NONE) goto error;

   

    status = VL53L0X_PerformRefCalibration(dev, &VhvSettings, &PhaseCal);//Ref参考校准

    if(status!=VL53L0X_ERROR_NONE) goto error;

    #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                 //

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif

    myrefSpadCount_readout = 6;

    myisApertureSpads_readout =1;

    Write_eeprom(refSpadCount_addr,&myrefSpadCount_readout,sizeof(myrefSpadCount_readout));

    Write_eeprom(isApertureSpads_addr,&myisApertureSpads_readout,sizeof(myisApertureSpads_readout));

    Read_eeprom(refSpadCount_addr,&myrefSpadCount_readout,sizeof(myrefSpadCount_readout));                   //把保存在EEPROM的refSpadcount的读出来

    Read_eeprom(isApertureSpads_addr,&myisApertureSpads_readout,sizeof(myisApertureSpads_readout));          //把保存在EEPROM的isApertureSpads的读出来

 

    status |= VL53L0X_set_reference_spads(&vl53l0x_dev,myrefSpadCount_readout,myisApertureSpads_readout);                //写进VL53L0x寄存器去            

    status |= VL53L0X_get_reference_spads(&vl53l0x_dev,&myrefSpadCount,&myisApertureSpads);      

   

    // Read_eeprom(VhvSettings_addr,&myVhvSetting_readout,sizeof(myVhvSetting_readout));                        //设置Ref

    // Read_eeprom(PhaseCal_addr,&myPhaseCal_readout,sizeof(myPhaseCal_readout));                              //Read_eeprom(PhaseCal_addr,&myPhaseCal_readout,sizeof(myPhaseCal_readout));

 

    // status |= VL53L0X_SetRefCalibration(&vl53l0x_dev,myVhvSetting_readout,myPhaseCal_readout);

    // status |= VL53L0X_GetRefCalibration(&vl53l0x_dev,&myVhvSettings,&myPhaseCal);


 

    myOffsetMicroMeter_readout = 9000;

    Write_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter_readout,sizeof(myOffsetMicroMeter_readout));

    Read_eeprom(pOffsetMicroMeter_addr,&myOffsetMicroMeter_readout,sizeof(myOffsetMicroMeter_readout));      //设置Offset

    status |= VL53L0X_set_offset_calibration_data_micro_meter(&vl53l0x_dev,myOffsetMicroMeter_readout);     //把保存在EEPROM的offset补偿写进VL53L0x寄存器去

    status |= VL53L0X_get_offset_calibration_data_micro_meter(&vl53l0x_dev,&myOffsetMicroMeter);            //读取VL53L0x的offset进行验证    

 

    myXTalkCompensationRateMegaCps_readout = 57;

    Write_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps_readout,sizeof(myXTalkCompensationRateMegaCps_readout));

    Read_eeprom(pXTalkCompensationRateMegaCps_addr,&myXTalkCompensationRateMegaCps_readout,sizeof(myXTalkCompensationRateMegaCps_readout));  //设置XTALK

       

    status |= VL53L0X_SetXTalkCompensationRateMegaCps(&vl53l0x_dev,myXTalkCompensationRateMegaCps_readout);       //把原来校准数据写入VL53L0x

    status |= VL53L0X_GetXTalkCompensationRateMegaCps(&vl53l0x_dev,&myXTalkCompensationRateMegaCps);              //验证一下

    status |= VL53L0X_SetXTalkCompensationRateMegaCps(&vl53l0x_dev,ENABLE);                                       //

 

                         

    #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                 //

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif                                                                       //重复做

     status = VL53L0X_SetDeviceMode(dev,VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING);//使能连续定时测量模式

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                 //

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif

     status = VL53L0X_SetInterMeasurementPeriodMilliSeconds(dev,Mode_data[mode].intertiming);//设置两次测量之间的时间

     if(status!=VL53L0X_ERROR_NONE) goto error;

    #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                 //

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif

     status = VL53L0X_SetLimitCheckEnable(dev,VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,1);//使能SIGMA范围检查

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                 //

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif

     status = VL53L0X_SetLimitCheckEnable(dev,VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,1);//使能信号速率范围检查

     if(status!=VL53L0X_ERROR_NONE) goto error;

    #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                

    #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

    #endif

     status = VL53L0X_SetLimitCheckValue(dev,VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,Mode_data[mode].sigmaLimit);//设定SIGMA范围

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_SetLimitCheckValue(dev,VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,Mode_data[mode].signalLimit);//设定信号速率范围范围

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

 

   

 

     status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(dev,Mode_data[mode].timingBudget);//设定完整测距最长时间

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_SetVcselPulsePeriod(dev, VL53L0X_VCSEL_PERIOD_PRE_RANGE, Mode_data[mode].preRangeVcselPeriod);//设定VCSEL脉冲周期

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_SetVcselPulsePeriod(dev, VL53L0X_VCSEL_PERIOD_FINAL_RANGE, Mode_data[mode].finalRangeVcselPeriod);//设定VCSEL脉冲周期范围

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_StopMeasurement(dev);//停止测量

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif    

     status = VL53L0X_SetInterruptThresholds(dev,VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING,AlarmModes.ThreshLow, AlarmModes.ThreshHigh);

     if(status!=VL53L0X_ERROR_NONE) goto error;            //设定触发中断上=150mm、下限值 = 60mm

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                  

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_SetGpioConfig(dev,0,VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING,AlarmModes.VL53L0X_Mode,VL53L0X_INTERRUPTPOLARITY_LOW);//VL53L0X_Mode设置中断在哪个区段;VL53L0X_INTERRUPTPOLARITY_LOW设置中断会产生下降沿

     if(status!=VL53L0X_ERROR_NONE) goto error;

     #if(defined(USE_TIME)) && (USE_TIME == TRUE)

      mDelaymS(2);                                

     #else

      CH58X_LowPower(RTC_GetCycle32k()+TIME_CONVER(2));

     #endif

     status = VL53L0X_ClearInterruptMask(dev,0);//清除VL53L0X中断标志位

     

     error://错误信息

     if(status!=VL53L0X_ERROR_NONE)

     {

        // print_pal_error(status);

        return ;

     }

 

     valver.timed_read_flag = 0;

     VL53L0X_StartMeasurement(dev);//启动测量

     

    //  printf("Start Measurement!\r\n");

     exti_init();                  //中断初始化

}