<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Including specific sensor header files</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79080/including-specific-sensor-header-files</link><description>Hi everyone, 
 I have a board based on thingy91. I have lis2dh and adxl372 sensors on it. They are both connected via SPI, and I&amp;#39;ve added this to my overlay file: 
 
 Also I&amp;#39;ve enabled the sensors in the prj.conf. I am able to initialize and get sensor</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 10 Sep 2021 11:19:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79080/including-specific-sensor-header-files" /><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/329011?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2021 11:19:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d82073f-67cd-4fd6-87bf-4e7e8ff6b118</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;&lt;span&gt;I&amp;#39;m not able to reproduce this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could you upload a small sample that reproduces this? (If you have done changes to Zephyr, add those files as well.)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327647?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 13:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84734cbe-0b17-459b-b71c-ab1ab1b2005e</guid><dc:creator>Aleksa</dc:creator><description>&lt;p&gt;I have tried to make my own driver(because I feel that the sensor API is way too limited for these two sensors). I don&amp;#39;t want to edit the zephyr unless I really have to(makes it harder to update ncs versions if I just edit it whenever I don&amp;#39;t like how it works). For example in the adxl372.c there is a&amp;nbsp;&lt;strong&gt;adxl372_bus_access()&amp;nbsp;&lt;/strong&gt;function, that extracts some configuration and in the end calls:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;return spi_transceive(adxl372_data-&amp;gt;bus, &amp;amp;adxl372_data-&amp;gt;spi_cfg, &amp;amp;tx, &amp;amp;rx);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When I try to make the same function in my own code, it says spi_cfg is not a part of the&amp;nbsp;&lt;strong&gt;&lt;em&gt;struct adxl372_data.&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&lt;/em&gt;But it definitely has to be a part of it, since I&amp;#39;ve set&amp;nbsp;&lt;strong&gt;&lt;em&gt;CONFIG_ADXL372_SPI=y.&amp;nbsp;&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;Same happens with the lis2dh, where it doesn&amp;#39;t allow access to the spi part of the configuration.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PS: Before I&amp;#39;ve tried accessing these fields that depend on whether or not the sensor is used via spi, my code did build too. Could you please try accessing them too?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327635?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 13:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:573d4622-11e0-41da-8e3c-2fb6e6d954a8</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;So far I&amp;#39;m not able to reproduce this.&lt;/p&gt;
&lt;p&gt;Testing with&amp;nbsp;asset_tracker_v2. I modified thingy91_nrf9160ns.overlay so it looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/ {
        aliases {
                temp-sensor = &amp;amp;bme680;
                humidity-sensor = &amp;amp;bme680;
                accelerometer = &amp;amp;adxl362;
        };
};

&amp;amp;i2c2 {
        bme680: bme680@76 {};
};

&amp;amp;spi3 {
        adxl362: adxl362@0 {};
        
        lis2dh@2 {
                compatible = &amp;quot;st,lis2dh&amp;quot;;
                label = &amp;quot;LIS2DH&amp;quot;;
                spi-max-frequency = &amp;lt;8000000&amp;gt;;
                reg = &amp;lt;0&amp;gt;;
                irq-gpios = &amp;lt;&amp;amp;gpio0 9 0&amp;gt;;
        };
};


&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added this to&amp;nbsp;&lt;span&gt;CMakeLists.txt :&lt;/span&gt;&lt;br /&gt;zephyr_include_directories(${ZEPHYR_BASE}/drivers/sensor/lis2dh)&lt;/p&gt;
&lt;p&gt;and added&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#include&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;lt;lis2dh.h&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;to main.c, it compiled without any warnings or errors.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327480?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 16:25:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8b9b659-b3bd-4021-b802-ab8a713da74e</guid><dc:creator>Aleksa</dc:creator><description>&lt;p&gt;Actually I&amp;#39;ve posted the wrong output, but I use spi3 now and the issue is still the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327473?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 15:42:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2e96bda-a889-4866-a3d6-9c13db99a1a2</guid><dc:creator>Sigurd</dc:creator><description>[quote user="Aleksa"]I&amp;#39;ve changed to the spi3, [/quote]
&lt;p&gt;&amp;nbsp;Could you use and upload that file instead? The one you are using now is still using spi0&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/8130.pastedimage1630424544423v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327465?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 15:24:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97fe73c8-b2e0-4f1e-bb5d-4af9ab093682</guid><dc:creator>Aleksa</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8345.CMakeLists.txt"&gt;devzone.nordicsemi.com/.../8345.CMakeLists.txt&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0815.zephyr.dts"&gt;devzone.nordicsemi.com/.../0815.zephyr.dts&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here are the two files. Here is ther error message(we use some build script to set things up for cmake before running it).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;MY_PATH&amp;gt;/bsp_sensor.c:122:53: error: &amp;#39;const union lis2dh_bus_cfg&amp;#39; has no member named &amp;#39;spi_cfg&amp;#39;
  122 |     const struct spi_config *spi_cfg = &amp;amp;cfg-&amp;gt;bus_cfg.spi_cfg-&amp;gt;spi_conf;
      |                                                     ^
&amp;lt;MY_PATH&amp;gt;/bsp_sensor.c: In function &amp;#39;bsp_sensor_lis3dh_spi_read&amp;#39;:
&amp;lt;MY_PATH&amp;gt;/bsp_sensor.c:159:53: error: &amp;#39;const union lis2dh_bus_cfg&amp;#39; has no member named &amp;#39;spi_cfg&amp;#39;
  159 |     const struct spi_config *spi_cfg = &amp;amp;cfg-&amp;gt;bus_cfg.spi_cfg-&amp;gt;spi_conf;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327427?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 12:52:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1938424-cc17-45c6-8372-605556055919</guid><dc:creator>Sigurd</dc:creator><description>[quote user="Aleksa"]By the way is the reason why you suggested this because the pins I use are pins of the spi3 or is it something else?[/quote]
&lt;p&gt;&amp;nbsp;Yes, It&amp;#39;s what the default thingy91 board is configured for. See this:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L128"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L128&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;+ also if you are using uart0, then you cannot use spi0 at the same time, since they share the same memory ID/address:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/memory.html#topic"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf9160/memory.html#topic&lt;/a&gt;&lt;/p&gt;
[quote user="Aleksa"]Is this&amp;nbsp;&lt;em&gt;zephyr.dts&lt;/em&gt; a final output of the overlay and the default dts files?[/quote]
&lt;p&gt;&amp;nbsp;Yes, correct. Can you upload it ? and your&amp;nbsp;CMakeLists.txt file ?&lt;/p&gt;
&lt;p&gt;Also, if there are other spi devices on spi3, you should use a unique device instance number for&amp;nbsp;&lt;span&gt;lis2dh, change&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;lis2dh@&lt;strong&gt;0&lt;/strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;{&lt;br /&gt;compatible = &amp;quot;st,lis2dh&amp;quot;;&lt;br /&gt;label = &amp;quot;LIS2DH&amp;quot;;&lt;br /&gt;spi-max-frequency = &amp;lt;8000000&amp;gt;;&lt;br /&gt;reg = &amp;lt;0&amp;gt;;&lt;br /&gt;irq-gpios = &amp;lt;&amp;amp;gpio0 9 0&amp;gt;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;p&gt;&lt;span&gt;lis2dh@&lt;/span&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span&gt;compatible = &amp;quot;st,lis2dh&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;label = &amp;quot;LIS2DH&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;spi-max-frequency = &amp;lt;8000000&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;reg = &amp;lt;0&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;irq-gpios = &amp;lt;&amp;amp;gpio0 9 0&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;};&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327211?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 12:18:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9797fa1-7c44-4393-b869-b451c6812c0a</guid><dc:creator>Aleksa</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve changed to the spi3, it didn&amp;#39;t help. By the way is the reason why you suggested this because the pins I use are pins of the spi3 or is it something else?&lt;/p&gt;
&lt;p&gt;Yes I do have lis2dh device in the zephyr.dts. Is this&amp;nbsp;&lt;em&gt;zephyr.dts&lt;/em&gt; a final output of the overlay and the default dts files?&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Aleksa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327183?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 11:20:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b87ab5eb-bac9-4301-911e-70088243cf8d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Are you sure the overlay is being applied? Check if you have the&amp;nbsp;lis2dh device in build_folder/zephyr/zephyr.dts&lt;/p&gt;
&lt;p&gt;And for the overlay, don&amp;#39;t use spi0, use&amp;nbsp;&lt;span&gt;spi3 instead.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including specific sensor header files</title><link>https://devzone.nordicsemi.com/thread/327125?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 08:02:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d56f066-c761-4830-86e7-3067f11e3a62</guid><dc:creator>Aleksa</dc:creator><description>&lt;p&gt;Additionally, CMakeLists.txt in both lis2dh and adxl372 don&amp;#39;t use the zephyr_include_directories command, which makes it harder to include them any other way.&amp;nbsp;I&amp;#39;ve tried adding&amp;nbsp;&lt;em&gt;zephyr_include_directories(.)&lt;/em&gt;&amp;nbsp;but I still get the same error&amp;nbsp;for lis2dh.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>