他们逼我做卧底

VL53L1 laser ranging

 
Overview

VL53L1X is different from the VL53L0X module. The measured distance of this module is within four meters. You can add a mold to it to increase its performance. The IIC interface has better accuracy, but it is more difficult to weld and requires higher welding requirements.

 

 

The analog IIC is written as follows:

uint8_t VL_IIC_Write_1Byte(uint8_t SlaveAddress, uint16_t REG_Address, uint8_t REG_data)
{
    IIC_start();
    IIC_Send_Byte(SlaveAddress );
    if (IIC_wait_ack())
    {
        IIC_stop(); //Release the bus
        return 1; //Exit if no response
    }
    IIC_Send_Byte(REG_Address >> 8);

    if (IIC_wait_ack()) //Wait for ACK
    {
        IIC_stop();
        return 1;
    }


    IIC_Send_Byte(REG_Address & 0x00ff);

    if (IIC_wait_ack()) //Wait for ACK
    {
        IIC_stop();
        return 1;
    }


    delay_ms(1);
    IIC_Send_Byte(REG_data);


    if (IIC_wait_ack()) //Wait for ACK
    {
        IIC_stop();
        return 1;
    }


    IIC_stop();
    return 0;
}

 
 
 
 
 

uint8_t VL_IIC_Read_1Byte(uint8_t SlaveAddress, uint16_t REG_Address, uint8_t *REG_data)
{
    IIC_start();
    IIC_Send_Byte(SlaveAddress); //Send write command


    if (IIC_wait_ack())
    {
        IIC_stop(); //Release the bus
        return 1; //Exit if no response
    }


    IIC_Send_Byte(REG_Address >> 8);

    if (IIC_wait_ack())
    {
        IIC_stop(); //Release the bus
        return 1; //Exit if no response
    }


    IIC_Send_Byte(REG_Address & 0x00ff);

    if (IIC_wait_ack())
    {
        IIC_stop(); //Release the bus
        return 1; //Exit if no response
    }


    delay_ms(1);
    IIC_start();


    IIC_Send_Byte(SlaveAddress | 0x01); //Send read command

    if (IIC_wait_ack())
    {
        IIC_stop(); //Release the bus
        return 1; //Exit if no response
    }


    *REG_data = IIC_Read_Byte(0);
    IIC_stop();


    return 0;
}
 
 
Test code:
 
uint8_t VL_Init(void)
{
    uint8_t res;
    IIC_Init();

    VL_IIC_Read_1Byte(VL_ADDR, module_type, &res);
    if (res == 0xCC) //The device ID is correct
    {
        UART_printf(UART0_BASE, "SUCCESS! ");
          return 1;
    }
    else
    {

        UART_printf(UART0_BASE, "failed! ");
        
    }
      return 0;
}

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-20 01:09:15

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号