Interfacing IMU Sensor (LSM6DSL) with SPI

Hi

I am using nrf52840dk- nrf52840 board to interface the IMU Sensor using SPI instead of I2C using nrf connect sdk for vs code.
But I am facing error.

Below I have attached the overlay file I created for LSM6DSL. I haven't changed anything in the main.c and I didn't changed anything in the prj.confg file also.

In the main.c there is if loop

if (!device_is_ready(lsm6dsl_dev)) {
        printk("sensor: device not ready.\n");
        return;
    }

When I buid my code and try to debug the code it is coming into this if loop showing device is not ready. Can Someone help me with this.

Note:I didn't changed anything in the main.c

       
&qspi {
    status = "disabled";
};

&pinctrl {
    spi1_default: spi1_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 1, 3)>,
                <NRF_PSEL(SPIM_MOSI, 1, 2)>,
                <NRF_PSEL(SPIM_MISO, 1, 5)>;
        };
    };

    spi1_sleep: spi1_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 1, 3)>,
                <NRF_PSEL(SPIM_MOSI, 1, 2)>,
                <NRF_PSEL(SPIM_MISO, 1, 5)>;
            low-power-enable;
        };
    };
};


&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
    lsm6dsl1: lsm6dsl@0{
        compatible = "st,lsm6dsl";
        reg = <0x0>;
        spi-max-frequency =<100000>;
        label ="lsm6dsl";

    };
};

In the above overlay file I added a node for lsm6dsl1 with st,lsm6dsl compatible.
Parents
  • There are only a few things that would cause this. Either the initialization function in the driver for LSM6DSL is failing (it would print an error) or the device information can not be found in the device tree.

    Looking at the driver in "..\ncs\v2.0.0\zephyr\drivers\sensor\lsm6dsl\lsm6dsl.c", if the initialization fails you will see one of two possible errors:

    1. LOG_ERR("Failed to initialize sensor bus");

    2. LOG_ERR("Failed to initialize chip");

    So if you have logging enabled and odn't see either of these errors then the driver can't find the device information from the device tree. How are you getting the variable "lsm6dsl_dev"?

Reply
  • There are only a few things that would cause this. Either the initialization function in the driver for LSM6DSL is failing (it would print an error) or the device information can not be found in the device tree.

    Looking at the driver in "..\ncs\v2.0.0\zephyr\drivers\sensor\lsm6dsl\lsm6dsl.c", if the initialization fails you will see one of two possible errors:

    1. LOG_ERR("Failed to initialize sensor bus");

    2. LOG_ERR("Failed to initialize chip");

    So if you have logging enabled and odn't see either of these errors then the driver can't find the device information from the device tree. How are you getting the variable "lsm6dsl_dev"?

Children
Related