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 Reply
  • So I printed out the log messages, found that it's because I didn't set the irq-gpios in overlay. Now everything works as expected.

    st_lsm6dsl: &spi3 {

    compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi3_default>;
    pinctrl-1 = <&spi3_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
    lsm6dsl: lsm6dsl@0 {
    compatible = "st,lsm6dsl";
    status = "okay";
    spi-max-frequency = <10000000>;
    reg = <0>;
    irq-gpios = <&gpio0 9 0>;
    };
    };
Children
Related