簡體   English   中英

VL53L0x 傳感器測距錯誤。 如何解決錯誤?

[英]VL53L0x sensor Ranging error. How to solve the error?

我正在嘗試將 vl53l0x 傳感器與我的 atSamE51A19 controller 接口。 我可以將數據發送到傳感器。 由於它已建立連接,我發送識別碼並響應。 但是進一步的初始化和測距不起作用。

我在我的 sam 板上使用 stm 庫實現。 [stmArduinoLib][1] 我所做的唯一更改是在讀寫函數中。 它使用的是 stm 基本函數,但我使用的是不同的函數。

    /****************** Write and read functions from I2C *************************/

VL53L0X_Error VL53L0X::VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count)
{
    int status;

    status = VL53L0X_I2CWrite(index, pdata, (uint16_t) count);
    if (status == 0)
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    else
    {
        status = VL53L0X_ERROR_NONE;
    }
    return status;      
}

VL53L0X_Error VL53L0X::VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count)
{
    int status;

    if (count >= VL53L0X_MAX_I2C_XFER_SIZE)
    {
        status = VL53L0X_ERROR_INVALID_PARAMS;
    }

    status = VL53L0X_I2CRead(index, pdata, (uint16_t) count);

    return status;  
}

VL53L0X_Error VL53L0X::VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data)
{
    int status;

    status = WriteRegister(index, data);    //VL53L0X_I2CWrite(index, &data, 1);

    if (status == 0)
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    else
    {
        status = VL53L0X_ERROR_NONE;
    }

    return status;  
}

VL53L0X_Error VL53L0X::VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data)
{
    int status;
    int32_t status_int;
    alignas(2) uint8_t buffer[2];

    buffer[0] = data >> 8;
    buffer[1] = data & 0x00FF;

    status_int = VL53L0X_I2CWrite(index, (uint8_t*) buffer, 2);

    // buffer[0] = MSB
    // buffer[1]
    // buffer[2]
    // buffer[3] = LSB
    if (status_int == 0)
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    else
    {
        status = VL53L0X_ERROR_NONE;
    }

    return status;  
}

VL53L0X_Error VL53L0X::VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data)
{
    int status;
    int32_t status_int;
    alignas(2) uint8_t buffer[4];

    buffer[0] = (data >> 24) & 0xFF;                // MSB
    buffer[1] = (data >> 16) & 0xFF;
    buffer[2] = (data >> 8) & 0xFF;
    buffer[3] = (data >> 0) & 0xFF;                 // LSB
    status_int = VL53L0X_I2CWrite(index, buffer, 4);

    if (status_int == 0)
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    else
    {
        status = VL53L0X_ERROR_NONE;
    }

    return status;  
}

VL53L0X_Error VL53L0X::VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data)
{
    int status = VL53L0X_ERROR_NONE;

    status = ReadRegister(index, *data);    //
    if (status)
    {
        status = VL53L0X_ERROR_NONE;
        return status;
    }
    else
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    return status;
}

VL53L0X_Error VL53L0X::VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data)
{
    int status = 0;
    uint8_t buffer[2] =
    { 0, 0 };

    status = VL53L0X_I2CRead(index, buffer, 2);
    if (status == 0)
    {
        *data = (uint16_t) (buffer[0] << 8) | (buffer[1] & 0xFF);       // | ? +
    }

    return status;          
}

VL53L0X_Error VL53L0X::VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data)
{
    int status;
    uint8_t buffer[4] =
    { 0, 0, 0, 0 };

    status = VL53L0X_I2CRead(index, buffer, 4);
    if (!status)                                    // use OR
    {
        *data = ((uint32_t) buffer[0] << 24) | ((uint32_t) buffer[1] << 16) | ((uint32_t) buffer[2] << 8) | (uint32_t) buffer[3];
    }
    return status;

}

VL53L0X_Error VL53L0X::VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData)
{
    int status;
    uint8_t buffer = 0;

    /* read data direct onto buffer */
    status = VL53L0X_I2CRead(index, &buffer, 1);
    if (!status)
    {
        buffer = (buffer & AndData) | OrData;
        status = VL53L0X_I2CWrite(index, &buffer, (uint8_t) 1);
    }

    if (status == 0)
    {
        status = VL53L0X_ERROR_CONTROL_INTERFACE;
    }
    else
    {

        status = VL53L0X_ERROR_NONE;
    }
    return status;
}

VL53L0X_Error VL53L0X::VL53L0X_I2CWrite(uint8_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite)
{
    return WriteRegisters(RegisterAddr, pBuffer, NumByteToWrite);
}

VL53L0X_Error VL53L0X::VL53L0X_I2CRead(uint8_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead)
{
    alignas(2) uint8_t vpBuffer[5];
    /*  dev_i2c->beginTransmission(((uint8_t) (((DeviceAddr) >> 1) & 0x7F)));
     */

    if (ReadRegisters(RegisterAddr, vpBuffer, NumByteToRead))
    {
        pBuffer = vpBuffer;
        return 0;
    }

    return 1;
}

在這個函數中,我不是每次都發送設備地址,只是發送索引和數據。 在構造函數中,我只設置了一次地址。 我使用 Status = VL53L0X_PerformRefSpadManagement(Device, &refSpadCount, &isApertureSpads);時遇到的唯一錯誤這個 function。 在初始化中。 不知道如何解決這個問題。 試圖將模式更改為無幫助的連續模式。 注意:傳感器與 arduino 一起工作正常。 [1]: https://github.com/stm32duino/VL53L0X

我找到了一個新的可能解決這個問題的方法,因為我花了2天的時間解決它,我覺得我需要與大家分享。 以下是解決方案的摘要:

  1. 供電問題 1在設置 function 中添加 50ms 延遲(顯然是在傳感器初始化之前)。 這樣,Vin 將有足夠的時間達到傳感器所需的水平,如上一條消息 (ocrdu) 中所述
  2. 供電問題 2 :這個傳感器比其他傳感器要求更高,通常你板子的 5V 引腳會比 3v3 做得更好 如果同時連接了多個傳感器,則將它們全部斷開以檢查它們是否正在使用我們的vl53l0x所需的電源
  3. 供電問題3 :如果用外接電源供電,與板子統一接地,別忘了
  4. SCL - SDA 弱信號添加一個上拉(從每個通道到 vin 的 2k2 - 4k7) ,這樣信號會表現得更好,這可能是問題
  5. 焊接問題確保每個 header 引腳焊接良好 我發現很多焊接不良的情況。 小墊子無濟於事。 建議使用萬用表檢查接頭和應連接的焊盤之間的連續性
  6. XSHUT 沒有上拉:我的問題,這是 AZDelivery 板說它在 XSHUT 中有上拉(就像啟用一樣)。 但它可能是錯誤的,或者實施不當。 Xshut 需要很高,3v3/5v ,否則,傳感器將無法工作。 將 XSHUT 橋接到 Vin 或實現上拉,問題將得到解決。
  • 我正在使用 adafruit 的庫 1.1.2,它可以工作,帶上拉,不帶上拉,連接到 5V 並連接到 3V3,延遲為 50ms,並將 XSHUT 連接到高電平(3V3 / Vin)
  • 我的主板是 AZDelivery 的 vl53l0x(5 歐元亞馬遜)
  • 我已經用 arduino nano 和 ESP32 測試了傳感器,兩者都工作正常

希望你們覺得這很有用<3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM