2020-11-23 01:03 AM
API Status: -6 : Range error
===============================
//my code
.....
if(Status == VL53L0X_ERROR_NONE)
{
// printf ("Call of VL53L0X_StaticInit\n");
Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization
print_pal_error(Status);
}
if(Status == VL53L0X_ERROR_NONE)
{
// printf ("Call of VL53L0X_PerformRefCalibration\n");
Status = VL53L0X_PerformRefCalibration(pMyDevice,
&VhvSettings, &PhaseCal); // Device Initialization
print_pal_error(Status); //-> API Status: -6 : Range error
}
.....
VL53L0X_Error VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
uint8_t *pPhaseCal)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
LOG_FUNCTION_START("");
Status = VL53L0X_perform_ref_calibration(Dev, pVhvSettings,
pPhaseCal, 1);
//Status = 0xFA
LOG_FUNCTION_END(Status);
return Status;
}
VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV Dev,
uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
uint8_t SequenceConfig = 0;
/* store the value of the sequence config,
* this will be reset before the end of the function
*/
SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
/* In the following function we don't save the config to optimize
* writes on device. Config is saved and restored only once. */
Status = VL53L0X_perform_vhv_calibration(
Dev, pVhvSettings, get_data_enable, 0);
//Status = 0xFA
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_perform_phase_calibration(
Dev, pPhaseCal, get_data_enable, 0);
if (Status == VL53L0X_ERROR_NONE) {
/* restore the previous Sequence Config */
Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
SequenceConfig);
if (Status == VL53L0X_ERROR_NONE)
PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
}
return Status;
}
VL53L0X_Error VL53L0X_perform_vhv_calibration(VL53L0X_DEV Dev,
uint8_t *pVhvSettings, const uint8_t get_data_enable,
const uint8_t restore_config)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
uint8_t SequenceConfig = 0;
uint8_t VhvSettings = 0;
uint8_t PhaseCal = 0;
uint8_t PhaseCalInt = 0;
/* store the value of the sequence config,
* this will be reset before the end of the function
*/
if (restore_config)
SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
/* Run VHV */
Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0x01);
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_perform_single_ref_calibration(Dev, 0x40);
//Status = 0xFA
/* Read VHV from device */
if ((Status == VL53L0X_ERROR_NONE) && (get_data_enable == 1)) {
Status = VL53L0X_ref_calibration_io(Dev, 1,
VhvSettings, PhaseCal, /* Not used here */
pVhvSettings, &PhaseCalInt,
1, 0);
} else
*pVhvSettings = 0;
if ((Status == VL53L0X_ERROR_NONE) && restore_config) {
/* restore the previous Sequence Config */
Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
SequenceConfig);
if (Status == VL53L0X_ERROR_NONE)
PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
}
return Status;
}
---
VL53L0X_Error VL53L0X_perform_single_ref_calibration(VL53L0X_DEV Dev,
uint8_t vhv_init_byte)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START,
VL53L0X_REG_SYSRANGE_MODE_START_STOP |
vhv_init_byte);
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_measurement_poll_for_completion(Dev);
//Status = 0xFA
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_ClearInterruptMask(Dev, 0);
if (Status == VL53L0X_ERROR_NONE)
Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START, 0x00);
return Status;
}
---
VL53L0X_Error VL53L0X_measurement_poll_for_completion(VL53L0X_DEV Dev)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
uint8_t NewDataReady = 0;
uint32_t LoopNb;
LOG_FUNCTION_START("");
LoopNb = 0;
do {
Status = VL53L0X_GetMeasurementDataReady(Dev, &NewDataReady);
//Status = 0xFA
if (Status != 0)
break; /* the error is set */
if (NewDataReady == 1)
break; /* done note that status == 0 */
LoopNb++;
if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
Status = VL53L0X_ERROR_TIME_OUT;
break;
}
VL53L0X_PollingDelay(Dev);
} while (1);
LOG_FUNCTION_END(Status);
return Status;
}
---
VL53L0X_Error VL53L0X_GetMeasurementDataReady(VL53L0X_DEV Dev,
uint8_t *pMeasurementDataReady)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
uint8_t SysRangeStatusRegister;
uint8_t InterruptConfig;
uint32_t InterruptMask;
LOG_FUNCTION_START("");
InterruptConfig = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
Pin0GpioFunctionality);
if (InterruptConfig ==
VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
Status = VL53L0X_GetInterruptMaskStatus(Dev, &InterruptMask);
//Status = 0xFA
if (InterruptMask ==
VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
*pMeasurementDataReady = 1;
else
*pMeasurementDataReady = 0;
} else {
Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_RANGE_STATUS,
&SysRangeStatusRegister);
if (Status == VL53L0X_ERROR_NONE) {
if (SysRangeStatusRegister & 0x01)
*pMeasurementDataReady = 1;
else
*pMeasurementDataReady = 0;
}
}
LOG_FUNCTION_END(Status);
return Status;
}
---
VL53L0X_Error VL53L0X_GetInterruptMaskStatus(VL53L0X_DEV Dev,
uint32_t *pInterruptMaskStatus)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
uint8_t Byte;
LOG_FUNCTION_START("");
Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_INTERRUPT_STATUS, &Byte);
*pInterruptMaskStatus = Byte & 0x07;
//Byte = 0x48, 0x4C
if (Byte & 0x18)
Status = VL53L0X_ERROR_RANGE_ERROR;
LOG_FUNCTION_END(Status);
return Status;
}