cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting VL53L0X Error: -6?

FPayn.1
Associate II

I have a single 'known good' VL53L0X hooked up to an Arduino Mega 2560 through a bidirectional level shifter. When I attempt to initialize it I get the following output:

Opening port
Port open
Arduino Hex VL53L0X Demo
In Adafruit_VL53L0X::begin(29,1,642)
VL53L0X Info:
Device Name: VL53L0X ES1 or later, Type: VL53L0X, ID: VL53L0CBV0DH/1$1
Rev Major: 1, Minor: 1
VL53L0X: StaticInit
VL53L0X: PerformRefSpadManagement
refSpadCount = 2226323456, isApertureSpads = 10
Status = -6
VL53L0X Error: -6
Failed to boot lidar_RF

It looks like the I2C bus is OK, as it is reading the device name and details correctly, but the VL53L0X_PerformRefSpadManagement() call returns with Status = -6, and the rest of the initialization is skipped.

I tried modifying the library code to skip the VL53L0X_PerformRefSpadManagement() call, but then VL53L0X_PerformRefCalibration() also returns with a -6 Status code.

Any idea what I'm doing wrong here?

TIA,

Frank

2 REPLIES 2
John E KVAM
ST Employee

Is it possible that you did not call DataInit() prior to calling StaticInit()?

"VL53L0X_DataInit() function is called one time, and it performs the device initialization.

To be called once and only once after device is brought out of reset."

It sets a bunch of registers into a more optimal state before the chip gets going.

I've seen this error before, but the customer found his bug and did not tell me what he changed.

But you did a good job of showing me what you called, and I did not see DataInit().

  • john

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
FPayn.1
Associate II

John,

Thanks for the prompt reply. I'm using the Adafruit library, and I believe all the setup code is in their begin() function, as follows:

/**************************************************************************/
boolean Adafruit_VL53L0X::begin(uint8_t i2c_addr, boolean debug, TwoWire *i2c) {
  uint32_t refSpadCount;
  uint8_t isApertureSpads;
  uint8_t VhvSettings;
  uint8_t PhaseCal;
 
//DEBUG!!
  Serial.print("In Adafruit_VL53L0X::begin(");
  Serial.print(i2c_addr,HEX); Serial.print(",");
  Serial.print(debug); Serial.print(",");
  Serial.print((uint16_t)i2c,HEX); Serial.println(")");
//DEBUG!!
 
  // Initialize Comms
  pMyDevice->I2cDevAddr = VL53L0X_I2C_ADDR; // default
  pMyDevice->comms_type = 1;
  pMyDevice->comms_speed_khz = 400;
  pMyDevice->i2c = i2c;
 
  pMyDevice->i2c->begin(); // VL53L0X_i2c_init();
 
//DEBUG!!
  //Serial.println("After pMyDevice->i2c->begin()");
//DEBUG!!
 
  // unclear if this is even needed:
  if (VL53L0X_IMPLEMENTATION_VER_MAJOR != VERSION_REQUIRED_MAJOR ||
      VL53L0X_IMPLEMENTATION_VER_MINOR != VERSION_REQUIRED_MINOR ||
      VL53L0X_IMPLEMENTATION_VER_SUB != VERSION_REQUIRED_BUILD) {
    if (debug) {
      Serial.println(F(
          "Found " STR(VL53L0X_IMPLEMENTATION_VER_MAJOR) "." STR(VL53L0X_IMPLEMENTATION_VER_MINOR) "." STR(
              VL53L0X_IMPLEMENTATION_VER_SUB) " rev " STR(VL53L0X_IMPLEMENTATION_VER_REVISION)));
      Serial.println(F("Requires " STR(VERSION_REQUIRED_MAJOR) "." STR(
          VERSION_REQUIRED_MINOR) "." STR(VERSION_REQUIRED_BUILD)));
    }
 
    Status = VL53L0X_ERROR_NOT_SUPPORTED;
 
    return false;
  }
 
  Status = VL53L0X_DataInit(&MyDevice); // Data initialization
 
  if (!setAddress(i2c_addr)) {
    return false;
  }
 
  Status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo);
 
  if (Status == VL53L0X_ERROR_NONE) {
    if (debug) {
      Serial.println(F("VL53L0X Info:"));
      Serial.print(F("Device Name: "));
      Serial.print(DeviceInfo.Name);
      Serial.print(F(", Type: "));
      Serial.print(DeviceInfo.Type);
      Serial.print(F(", ID: "));
      Serial.println(DeviceInfo.ProductId);
 
      Serial.print(F("Rev Major: "));
      Serial.print(DeviceInfo.ProductRevisionMajor);
      Serial.print(F(", Minor: "));
      Serial.println(DeviceInfo.ProductRevisionMinor);
    }
 
    if ((DeviceInfo.ProductRevisionMajor != 1) ||
        (DeviceInfo.ProductRevisionMinor != 1)) {
      if (debug) {
        Serial.print(F("Error expected cut 1.1 but found "));
        Serial.print(DeviceInfo.ProductRevisionMajor);
        Serial.print(',');
        Serial.println(DeviceInfo.ProductRevisionMinor);
      }
 
      Status = VL53L0X_ERROR_NOT_SUPPORTED;
    }
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    if (debug) {
      Serial.println(F("VL53L0X: StaticInit"));
    }
 
    Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    if (debug) {
      Serial.println(F("VL53L0X: PerformRefSpadManagement"));
    }
 
    Status = VL53L0X_PerformRefSpadManagement(
        pMyDevice, &refSpadCount, &isApertureSpads); // Device Initialization
 
    if (debug) {
      Serial.print(F("refSpadCount = "));
      Serial.print(refSpadCount);
      Serial.print(F(", isApertureSpads = "));
      Serial.println(isApertureSpads);
      Serial.print(F("Status = ")); Serial.println(Status);
    }
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    if (debug) {
      Serial.println(F("VL53L0X: PerformRefCalibration"));
    }
 
    Status = VL53L0X_PerformRefCalibration(pMyDevice, &VhvSettings,
                                           &PhaseCal); // Device Initialization
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
    if (debug) {
      Serial.println(F("VL53L0X: SetDeviceMode"));
    }
 
    Status = VL53L0X_SetDeviceMode(
        pMyDevice,
        VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode
  }
 
  // Enable/Disable Sigma and Signal check
  if (Status == VL53L0X_ERROR_NONE) {
    Status = VL53L0X_SetLimitCheckEnable(
        pMyDevice, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    Status = VL53L0X_SetLimitCheckEnable(
        pMyDevice, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    Status = VL53L0X_SetLimitCheckEnable(
        pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1);
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    Status = VL53L0X_SetLimitCheckValue(
        pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
        (FixPoint1616_t)(1.5 * 0.023 * 65536));
  }
 
  if (Status == VL53L0X_ERROR_NONE) {
    return true;
  } else {
    if (debug) {
      Serial.print(F("VL53L0X Error: "));
      Serial.println(Status);
    }
 
    return false;
  }
}