2024-01-07 05:28 PM
I have the Sparkfun version of the LSM6DSV16X. I used it with the Arduino IDE and everything works easily. I migrated that LSM6DSV16X board to using a Nordic nrf5340dk. There doesn't seem to be a working library for the LSM6DSV16X, but that is ok as I would like to control it directly over I2C.
I am able to read WHO_AM_I = 0x70. I am also able to read LSM6DSV16X registers that have default values.
What I can't do is read any values from "output" registers that should hold Accel and Gyro data. I imagine it's because I don't have the configuration bits set correctly as anything I read comes back 0x00.
I2C, IMU's, LSM6DSV16X, and the nrf5340 are fairly new to me, can you help me with steps to take to set the LSM6DSV16X up manually so that I can get the same Accel/Gyro output I was getting from the Arduino library?
This is the general idea of how I expected it would work. I believe that I am supposed to read registers 0x22-0x2D? Any advice would be appreciated.
i2c_buffer[0] = WHO_AM_I;
do{
err = i2c_write(i2c1_dev, i2c_buffer, 1, LSM6DSV16X_I2C_ADDRESS);
if(err < 0){
printk("(%d) Error writing to i2c device (0x%02x)\n", err, LSM6DSV16X_I2C_ADDRESS);
break;
}
err = i2c_read(i2c1_dev, i2c_buffer, 1, LSM6DSV16X_I2C_ADDRESS);
if(err < 0){
printk("(%d) Error reading i2c device (0x%02x)\n", err, LSM6DSV16X_I2C_ADDRESS);
break;
}
//THIS WORKS PERFECTLY.
printk("who am I: 0x%02x\n", i2c_buffer[0]);
//TRYING TO READ DATA...
i2c_buffer[0] = 0x22; //0x22-0x2D???
int readLen = 12;
err = i2c_write(i2c1_dev, i2c_buffer, 1, LSM6DSV16X_I2C_ADDRESS);
if(err < 0){
printk("(%d) Error writing to i2c device (0x%02x)\n", err, LSM6DSV16X_I2C_ADDRESS);
break;
}
err = i2c_read(i2c1_dev, i2c_buffer, readLen, LSM6DSV16X_I2C_ADDRESS);
if(err < 0){
printk("(%d) Error reading i2c device (0x%02x)\n", err, LSM6DSV16X_I2C_ADDRESS);
break;
}
for(uint8_t i = 0; i < readLen; i++){
printk("data: 0x%02x, ", i2c_buffer[i]);
}
printk("\n");
2024-01-07 07:04 PM
I realized I had an extra "write" where I shouldn't have... Here is the entire code with that corrected.
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>
#include "../../../../../../../../../nrf/blinky2/LSM6DSV16X_Register_Address_Map.h"
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
#define I2C_NODE DT_NODELABEL(i2c1)
static const struct device *i2c1_dev = DEVICE_DT_GET(I2C_NODE);
static uint8_t i2c_buffer[12];
int main(void)
{
int err;
if(!device_is_ready(i2c1_dev)){
printk("i2c1_dev not ready\n");
return 0;
}
while (1) {
i2c_buffer[0] = WHO_AM_I;
uint8_t i2c_read_buf[2];
do{
err = i2c_write_read(i2c1_dev, LSM6DSV16X_I2C_ADDRESS, i2c_buffer, 1, i2c_read_buf, 1);
printk("who am I v2: 0x%02x\n", i2c_read_buf[0]);
//Read DATA
i2c_buffer[0] = 0x22; //0x22-0x2D???
int readLen = 12;
err = i2c_read(i2c1_dev, i2c_buffer, readLen, LSM6DSV16X_I2C_ADDRESS);
if(err < 0){
printk("(%d) Error reading i2c device (0x%02x)\n", err, LSM6DSV16X_I2C_ADDRESS);
break;
}
for(uint8_t i = 0; i < readLen; i++){
printk("data: 0x%02x, ", i2c_buffer[i]);
}
printk("\n");
}while(false);
k_msleep(SLEEP_TIME_MS);
}
return 0;
}
2024-01-08 02:37 AM
Hi @mej ,
Welcome to ST Community!
I suggest you to have a look at our examples on github, for example you can find how to configure the sensor to read in polling mode here.
2024-02-01 12:39 AM
Hi @mej ,
Did the drivers help you?
2024-02-26 12:01 AM
Sorry, I got pulled away on other things... I believe they will help, but haven't been able to work on the project.