Configuring dts file for lis2h accelerometer

Hello 

I'm trying to build the lis2dh sample on my nRF 52840 board with the LIS3DH accelerometer 

I have an overlay file which I include in the build with -DDTC_OVERLAY_FILE=".." command
The overlay file looks like this

 #include "wearable_pinctl.dtsi"
/ 
 wearable_i2c: &i2c0 {
    compatible = "nordic,nrf-twi";
    status = "okay";
    pinctrl-0 = <&wearable_i2c_default>;
    pinctrl-1 = <&wearable_i2c_sleep>;
    pinctrl-names = "default", "sleep";

    lis2dh: lis2dh@???? {
        compatible = "st,lis2dh";
        reg = <0x????>;
        irq-gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>, <&gpio0 17 GPIO_ACTIVE_HIGH>;
    };

};
Several questions
1.
What should the address of the register be in the  ls2dh block above? How do I find that out? I've seen values 0x19, 0x30 and the like in various .dts files in the Zephyr repo
2..
I assume the "irq-gpios" are the INT 1 and INT2  in the schematic ? Please confirm that
3.
The sample has no  CONFIG_LIS2DHxxx defined in the prj.conf
There are multiple options. For example I'm interested in 
CONFIG_LIS2DH_MEASURE_TEMPERATURE and 
CONFIG_LIS2DH_TRIGGER
When I define them and the CONFIG_LIS2DH=y option I get a warning
"CONFIG_LIS2DH was assigned the value y, but got the value n. Missing dependencies:
DT_HAS_ST_LIS2DH_ENABLED"
If I try to enable it with
CONFIG_DT_HAS_ST_LIS2DH_ENABLED =y I get the warning
"Symbol CONFIG_DT_HAS_ST_LIS2DH_ENABLED cannot be set (has no prompt)"
How do I enable the options I'm interested in ?
4.
My accelerometer is really lis3dh. I've seen it defined in some dts files in the Zephyr repo 
But when I change "st,lis2dh" to "st,lis3dh" the code that fetches the device pointer
i.e
sensor = DEVICE_DT_GET_ONE(st_lis3dh);
fails with this error:
C:\vd\lis2dh-accelerometer\src\main.c:128: undefined reference to `__device_dts_ord_116'
It works fine if the in the lis2dh is used
How do I enable lis3dh ? Is there a reason to ?
Thank you
Parents
  • Hi,

    1.
    What should the address of the register be in the  ls2dh block above? How do I find that out? I've seen values 0x19, 0x30 and the like in various .dts files in the Zephyr repo

    You have to look at the datasheet for the sensor to see which I2C address(es) it uses, and how to configure them.

    2..
    I assume the "irq-gpios" are the INT 1 and INT2  in the schematic ? Please confirm that

    Correct. You can find the documentation for the properties here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.4.0/zephyr/build/dts/api/bindings/sensor/st%2Clis2dh-i2c.html#properties

    3.
    The sample has no  CONFIG_LIS2DHxxx defined in the prj.conf
    There are multiple options. For example I'm interested in 
    CONFIG_LIS2DH_MEASURE_TEMPERATURE and 
    CONFIG_LIS2DH_TRIGGER
    When I define them and the CONFIG_LIS2DH=y option I get a warning
    "CONFIG_LIS2DH was assigned the value y, but got the value n. Missing dependencies:
    DT_HAS_ST_LIS2DH_ENABLED"
    If I try to enable it with
    CONFIG_DT_HAS_ST_LIS2DH_ENABLED =y I get the warning
    "Symbol CONFIG_DT_HAS_ST_LIS2DH_ENABLED cannot be set (has no prompt)"
    How do I enable the options I'm interested in ?

    The driver is automatically enabled if the node is enabled in the device tree.

    To do this, you need to set "status" property to "okay" (similar to how it is done for the I2C node).

    If I try to enable it with
    CONFIG_DT_HAS_ST_LIS2DH_ENABLED =y I get the warning
    "Symbol CONFIG_DT_HAS_ST_LIS2DH_ENABLED cannot be set (has no prompt)"

    This will be set automatically from the device tree when the lis2dh node is enabled.

    4.
    My accelerometer is really lis3dh. I've seen it defined in some dts files in the Zephyr repo 
    But when I change "st,lis2dh" to "st,lis3dh" the code that fetches the device pointer
    i.e
    sensor = DEVICE_DT_GET_ONE(st_lis3dh);
    fails with this error:
    C:\vd\lis2dh-accelerometer\src\main.c:128: undefined reference to `__device_dts_ord_116'
    It works fine if the in the lis2dh is used
    How do I enable lis3dh ?

    Did you also change the lis2dh node in your device tree to be a lis3dh node instead?

    Is there a reason to ?

    I don't know the difference between the two devices and their drivers to answer that question properly.

    Best regards,

    Didrik

  • 1. 

    The only place in the lis3dh spec that talks about the i2c addresses that I could find  was here

    "The Slave ADdress (SAD) associated to the LIS3DH is 001100xb. The SDO/SA0 pad can be used to modify the less significant bit of the device address. If the SA0 pad is connected to the voltage supply, LSb is ‘1’ (address 0011001b) else if SA0 pad is connected to ground, the LSb value is ‘0’ (address 0011000b)."

    I tried both but devce_ready() function always returns false. Also in all the .dts files that use lis2dh and lis3dh in the Zephyr  repo the addresses are small, i.e 0x19, 0x18, etc

    3.

    Setting the  status to "okay"  got rid of the warning on CONFIG_LIS2DH symbol

    However setting CONFIG_LIS2DH_TRIGGER = y produces a build error that there is no prompt for this symbol and it  gets its value from other symbols. Which ones?

    4.

    Tried to replace "lis2dh" with "lis3dh" everywhere in the overlay file, still got the link error "undefined reference to `__device_dts_ord_116"

    Thanks

    Andy

  • AndyM said:
    (address 0011000b).
    AndyM said:
    (address 0011001b)

    These addresses are 0x18 and 0x19.

    AndyM said:
    However setting CONFIG_LIS2DH_TRIGGER = y produces a build error that there is no prompt for this symbol and it  gets its value from other symbols. Which ones?

    Looking at the Kconfig files where the options are defined are often helpful in these cases.

    In this case, you should set one of CONFIG_LIS2DH_TRIGGER_NONE, CONFIG_LIS2DH_TRIGGER_GLOBAL_THREAD or CONFIG_LIS2DH_TRIGGER_OWN_THREAD. If you select one of the last two, CONFIG_LIS2DH_TRIGGER will be set automatically.

    AndyM said:
    Tried to replace "lis2dh" with "lis3dh" everywhere in the overlay file, still got the link error "undefined reference to `__device_dts_ord_116"

    It looks like there are no separate driver for the lis3dh. Instead, it uses the same driver as the lis2dh.

    A node can have multiple compatible values, so you can have compatible = "st,lis3dh", "st,lis2dh"; in your node.

    Naming (the part before the @) the node "lis3dh", with compatible set to both "st,lis2dh" and "st,list2dh", and enabling both CONFIG_SENSOR and CONFIG_LIS2DH in my prj.conf seems to be working for me (at least, I am able to build the hello_world sample, and use DEVICE_DT_GET_ONE to get the sensor).

    If that doesn't work, you can try to look in <your build folder>/zephyr/include/generated/devicetree_generated.h what 116 refers to.

Reply
  • AndyM said:
    (address 0011000b).
    AndyM said:
    (address 0011001b)

    These addresses are 0x18 and 0x19.

    AndyM said:
    However setting CONFIG_LIS2DH_TRIGGER = y produces a build error that there is no prompt for this symbol and it  gets its value from other symbols. Which ones?

    Looking at the Kconfig files where the options are defined are often helpful in these cases.

    In this case, you should set one of CONFIG_LIS2DH_TRIGGER_NONE, CONFIG_LIS2DH_TRIGGER_GLOBAL_THREAD or CONFIG_LIS2DH_TRIGGER_OWN_THREAD. If you select one of the last two, CONFIG_LIS2DH_TRIGGER will be set automatically.

    AndyM said:
    Tried to replace "lis2dh" with "lis3dh" everywhere in the overlay file, still got the link error "undefined reference to `__device_dts_ord_116"

    It looks like there are no separate driver for the lis3dh. Instead, it uses the same driver as the lis2dh.

    A node can have multiple compatible values, so you can have compatible = "st,lis3dh", "st,lis2dh"; in your node.

    Naming (the part before the @) the node "lis3dh", with compatible set to both "st,lis2dh" and "st,list2dh", and enabling both CONFIG_SENSOR and CONFIG_LIS2DH in my prj.conf seems to be working for me (at least, I am able to build the hello_world sample, and use DEVICE_DT_GET_ONE to get the sensor).

    If that doesn't work, you can try to look in <your build folder>/zephyr/include/generated/devicetree_generated.h what 116 refers to.

Children
Related