Hi,
I am trying to get the data from the Lidar Lite V3 sensor via the I2C bus. However, I only receive a 0 back.
So my question is the implementation generally correct?
Lidar V3 datasheet: https://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf
Overlay file:
&arduino_i2c { /* i2c */
compatible = "nordic,nrf-twim";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
prj.conf file:
CONFIG_LOG=y CONFIG_I2C=y CONFIG_I2C_NRFX=y CONFIG_STDOUT_CONSOLE=y CONFIG_PRINTK=y
main.c file :
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
#define I2C_NODE DT_ALIAS(arduino_i2c)
#define LIDAR_I2C_ADDR 0x62
#define I2C_DEV_NAME DT_NODELABEL(arduino_i2c)
#define DELAY_TIME K_MSEC(500)
void main(void)
{
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_FAST) | I2C_MODE_CONTROLLER;
const struct device *const i2c_dev = DEVICE_DT_GET(I2C_DEV_NAME);
uint8_t data[2] = {0};
int i2c_device_ready, ret = 0;
if (i2c_dev == NULL || !device_is_ready(i2c_dev)) {
LOG_INF("I2C: Device is not ready.\n");
return;
}else
{
LOG_INF("I2C: Device is ready.\n");
}
if (i2c_configure(i2c_dev, i2c_cfg)) {
LOG_INF("I2C config failed\n");
return;
}
while (1)
{
ret = i2c_reg_write_byte(i2c_dev, LIDAR_I2C_ADDR, 0x00, 0x04);
if (ret) {
printk("Error writing to reg 0x00! error code (%d)\n", ret);
return;
}
while (!i2c_device_ready)
{
uint8_t ready = 55;
ret = i2c_reg_read_byte(i2c_dev, LIDAR_I2C_ADDR, 0x01, &ready);
if (ret) {
printk("Error reading reg 0x01! error code (%d)\n", ret);
return;
}
if (ready == 0){
i2c_device_ready = 1;
}
printk("data ready: %d \n", ready);
k_sleep(DELAY_TIME);
}
i2c_device_ready = 0;
ret = i2c_burst_read(i2c_dev, LIDAR_I2C_ADDR, 0x8f, &data, sizeof(data));
if (ret) {
printk("Error writing to FRAM! error code (%d)\n", ret);
return;
}
printk("data: %d \n", (data[0] << 8 + data[1]));
}
}