LSM6DSOX over SPI cant connect but works over I2C

I'm trying to use Adafruit LSM6DSOX (I think it's a misprint and it's actually LSM6DSO), regardless. I can get it to work using I2C but I need it over SPI. 

I have been racking my mind about what's wrong. I'm getting all kinds of configuration errors. 

First off, prj.conf

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=n
CONFIG_SPI=y
CONFIG_SENSOR=y
CONFIG_LSM6DSO=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
CONFIG_LSM6DSO was assigned the value y, but got the value n. Missing dependencies:
DT_HAS_ST_LSM6DSO_ENABLED
DTS is:
/dts-v1/;
#include <nordic/nrf5340_cpuapp_qkaa.dtsi>
#include "nrf5340_cpuapp_common.dts"

/ {
  model = "Nordic NRF5340 DK NRF5340 Application";
  compatible = "nordic,nrf5340-dk-nrf5340-cpuapp";

  chosen {
    zephyr,sram = &sram0_image;
    zephyr,flash = &flash0;
    zephyr,code-partition = &slot0_partition;
    zephyr,sram-secure-partition = &sram0_s;
    zephyr,sram-non-secure-partition = &sram0_ns;
  };

};

&arduino_header {
  gpio-map = <0 0 &gpio0 4 0>,
             <1 0 &gpio0 5 0>,
             <2 0 &gpio0 6 0>,
             <3 0 &gpio0 7 0>,
             <4 0 &gpio0 25 0>,
             <5 0 &gpio0 26 0>,
             <6 0 &gpio1 0 0>,
             <7 0 &gpio1 1 0>,
             <8 0 &gpio1 4 0>,
             <9 0 &gpio1 5 0>,
             <10 0 &gpio1 6 0>,
             <11 0 &gpio1 7 0>,
             <12 0 &gpio1 8 0>,
             <13 0 &gpio1 9 0>,
             <14 0 &gpio1 10 0>,
             <15 0 &gpio1 11 0>,
             <16 0 &gpio1 12 0>,
             <17 0 &gpio1 13 0>,
             <18 0 &gpio1 14 0>,
             <19 0 &gpio1 15 0>,
             <20 0 &gpio1 2 0>,
             <21 0 &gpio1 3 0>;
};

// &i2c1 {
//    lsm6dso: lsm6dso@6a {
//        compatible = "st,lsm6dso";
//        reg = <0x6a>;
//        irq-gpios = <&arduino_header 11 GPIO_ACTIVE_HIGH>; /* D5 */
//        int-pin = <2>;
//        gyro-odr = <1>;
//    };
// };


st_lsm6dso: &spi4 {
  compatible = "nordic,nrf-spim";
  status = "okay";
  cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
  lsm6dso: lsm6dso@0 {
    compatible = "st,lsm6dso";
    status = "okay";
    spi-max-frequency = <10000000>;
    reg = <0>;
  };
};
and in main()
  printf("Testing LSM6DSO sensor.\n\n");
  const struct device *const dev = DEVICE_DT_GET(DT_INST(0, st_lsm6dso));
  k_msleep(100);
  if (!device_is_ready(dev))
  {
    printk("%s: device not ready.\n", dev->name);
    return;
  }

  printf("Testing LSM6DSO sensor in polling mode.\n\n");
  test_polling_mode(dev);
Whatever I do I can't get it to work over SPI, any ideas?
It gets to the Device not ready
Parents
  • Hi,

    First of all, you should not make changes directly in the board files unless you are creating a custom board. Instead, you should create a devicetree overlay, such as for example nrf5340dk_nrf5340_cpuapp.overlay, and add the changes there. In this case, you should add the st_lsm6dso node in that file.

    As for the device not ready issue, you should use the nodelabel, or an alias, instead of instance number. Changing to the following should fix the issue:

    const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(st_lsm6dso));

    Best regards,
    Marte

Reply
  • Hi,

    First of all, you should not make changes directly in the board files unless you are creating a custom board. Instead, you should create a devicetree overlay, such as for example nrf5340dk_nrf5340_cpuapp.overlay, and add the changes there. In this case, you should add the st_lsm6dso node in that file.

    As for the device not ready issue, you should use the nodelabel, or an alias, instead of instance number. Changing to the following should fix the issue:

    const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(st_lsm6dso));

    Best regards,
    Marte

Children
Related