Using LSM6DSO sensor on NRF52832

Hello, 

I'm new to pretty much all of this, but I'll do my best to explain my issue. As the title says, I'm currently trying to get a LSM6DSO sensor to work with the NRF52832 board. I'm using the Nordic sample code for LSM6DSO and using VSCode to build it for the NRF52832. I was having issues with the devicetree not being able to find the sensor using DEVICE_DT_GET_ONE (this function initially returned a negative value), so I added an extra overlay file: 

arduino_i2c: &i2c0 {
    lsm6dso@6a {
        compatible = "st,lsm6dso";
        label = "LSM6DSO";
        reg = <0x6a>;
    };
};
This seemed to fix the issue. The only other thing I changed from the base project code was adding the lines
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
to my prj.conf file so that I could log any errors.
I've fully connected the sensor to the board and have verified the connections are correct using a colleagues code, so I don't think the connections are the issue. When I build and flash the code, this is the output I get:
As I said, I'm fairly new to how Nordic organizes code and devicetree, so I'm really just not sure what to do from here. Obviously, the code is running through its main function, but it gets an error when it tries to test the trigger mode. I believe the sample code is supposed to work with an ST board, so I think getting this code to work is just a matter of making small changes to the overlay files or the configuration files, although I could easily be wrong.
Any advice would be greatly appreciated, and let me know if I can provide any more information that might help. Thank you!
  • Hey, thank you for this super detailed response! I won't be using trigger mode for my application, so I just disabled it in the .conf file as you suggested. As soon as I did that, I was able to get actual readings from the sensor. Appreciate it!

  •  

    I wanted to confirm whether the following functions work with SPI. If they do, could you guide me on how to configure them? It would be helpful if you can provide driver code for the same.                                                           sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &x);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &y);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &z);

  • It should, to my knowledge at least. Most of the abstractions are protocol-agnostic once you have the devicetree/overlay configured for a sensor. 

  • Thanks for the quick response, this is my dts file

    	compatible = "x1";
    
    	chosen {
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};
    
    	aliases {
    		button = &button;
    		rgbled = &rgbled;
    		accel = &accel;
    		gyro = &gyro;
    	};
    
    	buttons {
    		compatible = "gpio-keys";
    		button: button {
    			gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
    		};
    	};
    };
    
    &uicr {
    	gpio-as-nreset;
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &gpio1 {
    	status = "okay";
    };
    
    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW> , <&gpio1 8 GPIO_ACTIVE_LOW>;
    	accel: lsm6dso32@0 {
    		compatible = "st,lsm6dso32";
    		reg = <0x0 >;
    		spi-max-frequency = <8000000>;
    		irq-gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
    		int-pin = <2>;
    		status = "okay";
    	};
    	gyro: lsm6dso32@1 {
    		compatible = "st,lsm6dso32";
    		reg = <0x1 >;
    		spi-max-frequency = <8000000>;
    		irq-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    		int-pin = <2>;
    		status = "okay";
    	};
    };
    
    &pwm0 {
    	status = "okay";
    	pinctrl-0 = <&pwm0_default>;
    	pinctrl-1 = <&pwm0_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &pwm1 {
    	status = "okay";
    	pinctrl-0 = <&pwm1_default>;
    	pinctrl-1 = <&pwm1_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &pwm2 {
    	status = "okay";
    	pinctrl-0 = <&pwm2_default>;
    	pinctrl-1 = <&pwm2_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &pinctrl {
    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 26)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 8)>;
    		};
    	};
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 26)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 8)>;
    			low-power-enable;
    		};
    	};
    	
    	pwm0_default: pwm0_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 23)>;
    			nordic,invert;
    		};
    	};
    
    	pwm0_sleep: pwm0_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 23)>;
    			low-power-enable;
    		};
    	};
    	pwm1_default: pwm1_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 21)>;
    			nordic,invert;
    		};
    	};
    
    	pwm1_sleep: pwm1_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 21)>;
    			low-power-enable;
    		};
    	};
    	pwm2_default: pwm2_default {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 13)>;
    			nordic,invert;
    		};
    	};
    
    	pwm2_sleep: pwm2_sleep {
    		group1 {
    			psels = <NRF_PSEL(PWM_OUT0, 0, 13)>;
    			low-power-enable;
    		};
    	};
    };
    
    &flash0 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x0 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0xc000 0x72000>;
    		};
    		slot1_partition: partition@7e000 {
    			label = "image-1";
    			reg = <0x7e000 0x72000>;
    		};
    		scratch_partition: partition@f0000 {
    			label = "image-scratch";
    			reg = <0xf0000 0xa000>;
    		};
    		storage_partition: partition@fa000 {
    			label = "storage";
    			reg = <0xfa000 0x6000>;
    		};
    	};
    };

    And this is my defconfig:

     

    # Copyright (c) 2024 Nordic Semiconductor ASA
    # SPDX-License-Identifier: Apache-2.0
    
    CONFIG_SOC_SERIES_NRF52X=y
    CONFIG_SOC_NRF52840_QIAA=y
    CONFIG_BOARD_X1=y
    
    # Enable MPU
    CONFIG_ARM_MPU=y
    
    # Enable hardware stack protection
    CONFIG_HW_STACK_PROTECTION=y
    
    # Enable driver interfaces
    CONFIG_SENSOR=y
    CONFIG_LED=y
    CONFIG_GPIO=y
    CONFIG_PWM=y
    CONFIG_I2C=y
    CONFIG_PINCTRL=y
    CONFIG_LSM6DSO=y
    CONFIG_LSM6DSR=y
    CONFIG_FUEL_GAUGE=y
    CONFIG_MAX17048=y
    CONFIG_IMU_THREAD_STACK_SIZE=2048
    CONFIG_SPI_NRFX=y
    CONFIG_SPI_LOG_LEVEL_DBG=y
    CONFIG_SENSOR_LOG_LEVEL_DBG=y
    CONFIG_LOG=y

    Could you please guide me what is missing here? Also, let me know if you need anything else. 

  • If you have a specific problem with your project, it may be more worthwhile to open a ticket so an official Nordic rep can be assigned to it. Work is ramping up on my end and I don't have as much time to debug others' projects. The Nordic Academy is also a great resource for understanding of Zephyr configurations and bringup, it was a huge help for me and I recommend going through their two crash courses if you haven't already.

Related