<?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>SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70515/spi-master-chip-select-in-overlay</link><description>Trying to convert a working sample for a BME280 sensor from I2C to SPI 
 nrfConnect 1.4 on nrf9160-DK 
 After looking at other SPI examples and noting the syntax I thought the .overlay should be like this 
 ``` 
 &amp;amp;spi3 { status = &amp;quot;okay&amp;quot;; sck-pin = &amp;lt;10</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Jan 2021 12:54:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70515/spi-master-chip-select-in-overlay" /><item><title>RE: SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/thread/290249?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 12:54:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2bb3bb0-0b26-4d7b-afc8-e816d6e44b5f</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m happy you made it work eventually &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/thread/290237?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 12:25:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1d35961-941a-446e-89c6-b5456ccd7426</guid><dc:creator>paul_tanner</dc:creator><description>&lt;p&gt;Many Thx Simon.&lt;/p&gt;
&lt;p&gt;Those quotes were the problem.&amp;nbsp; All fixed now.&lt;/p&gt;
&lt;p&gt;Regards, Paul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/thread/290233?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 12:04:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:188c1dbc-ef42-4e29-8479-9714cdb56d29</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Try changing&amp;nbsp;&lt;span&gt;&lt;code&gt;device_get_binding(&amp;quot;BME280_LABEL&amp;quot;)&lt;/code&gt; to&amp;nbsp;&lt;code&gt;device_get_binding(BME280_LABEL) &lt;/code&gt;(without the quotation marks &amp;quot;&amp;quot;). &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You could also just simply do&amp;nbsp;&lt;code&gt;device_get_binding(&amp;quot;BME280&amp;quot;)&lt;/code&gt; (use the label set in the overlay file) directly to make sure it works.&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;Additional comments:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If that doesn&amp;#39;t work, it is helpful to look at the file build/zephyr/zephyr.dts to see if the dts output is generated correctly.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sometimes the reason for device_get_binding() failing is because the associated init function has failed. The init function for the bme280 driver you&amp;#39;re using is &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/8b6686f731f90a4d672e2160172f672e06c3e1bb/drivers/sensor/bme280/bme280.c#L546"&gt;bme280_init()&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/thread/289802?ContentTypeID=1</link><pubDate>Mon, 18 Jan 2021 14:33:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdac67ec-be7d-471b-a89b-1a52f272afe9</guid><dc:creator>paul_tanner</dc:creator><description>&lt;p&gt;Thx Simon,&lt;/p&gt;
&lt;p&gt;I can also build with the above.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;At runtime I get:&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;p&gt;prepare to jump to Non-Secure image.&lt;br /&gt;[00:00:00.000,030] [0m&amp;lt;dbg&amp;gt; BME280.bme280_init: initializing BME280[0m&lt;br /&gt;[00:00:00.000,122] [0m&amp;lt;dbg&amp;gt; BME280.bme280_chip_init: ID OK[0m&lt;br /&gt;[00:00:00.001,647] [0m&amp;lt;dbg&amp;gt; BME280.bme280_init: BME280 OK[0m&lt;br /&gt;*** Booting Zephyr OS build v2.4.0-ncs1 ***&lt;br /&gt;[00:00:00.001,708] [0m&amp;lt;dbg&amp;gt; os.k_sched_unlock: scheduler unlocked (0x200102b0:0)[0m&lt;br /&gt;Starting BME280 test with SPI&lt;br /&gt;No device &amp;quot;BME280&amp;quot; found (); did initialization fail?&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;p&gt;I have double-checked the connections.&lt;/p&gt;
&lt;p&gt;Source:&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;p&gt;/*&lt;br /&gt;* Copyright (c) 2012-2014 Wind River Systems, Inc.&lt;br /&gt;* SPDX-License-Identifier: Apache-2.0&lt;br /&gt;* bme280 example converted to SPI&lt;br /&gt;*/&lt;/p&gt;
&lt;p&gt;#include &amp;lt;zephyr.h&amp;gt;&lt;br /&gt;#include &amp;lt;device.h&amp;gt;&lt;br /&gt;#include &amp;lt;devicetree.h&amp;gt;&lt;br /&gt;#include &amp;lt;drivers/sensor.h&amp;gt;&lt;/p&gt;
&lt;p&gt;#define BME280 DT_INST(0, bosch_bme280)&lt;br /&gt;//#undef DT_BOSCH_BME280_BUS_I2C&lt;br /&gt;//#define DT_BOSCH_BME280_BUS_SPI&lt;/p&gt;
&lt;p&gt;#if DT_NODE_HAS_STATUS(BME280, okay)&lt;br /&gt;#define BME280_LABEL DT_LABEL(BME280)&lt;br /&gt;#else&lt;br /&gt;#error Your devicetree has no enabled nodes with compatible &amp;quot;bosch,bme280&amp;quot;&lt;br /&gt;#define BME280_LABEL &amp;quot;&amp;lt;none&amp;gt;&amp;quot;&lt;br /&gt;#endif&lt;/p&gt;
&lt;p&gt;void main(void)&lt;br /&gt;{&lt;br /&gt; int i;&lt;br /&gt; printk(&amp;quot;Starting BME280 test with SPI \n&amp;quot;);&lt;/p&gt;
&lt;p&gt;const struct device *dev = device_get_binding(&amp;quot;BME280_LABEL&amp;quot;);&lt;br /&gt; if (dev == NULL) {&lt;br /&gt; printk(&amp;quot;No device \&amp;quot;%s\&amp;quot; found (); did initialization fail?\n&amp;quot;, BME280_LABEL);&lt;br /&gt; return;&lt;br /&gt; } else {&lt;br /&gt; printk(&amp;quot;Found device \&amp;quot;%s\&amp;quot;\n&amp;quot;, BME280_LABEL);&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;for (i = 1; i &amp;lt; 2; i++) {&lt;br /&gt; struct sensor_value temp, press, humidity;&lt;/p&gt;
&lt;p&gt;sensor_sample_fetch(dev);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &amp;amp;temp);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_PRESS, &amp;amp;press);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &amp;amp;humidity);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; printk(&amp;quot;Environmental Temperature: %d.%02d Degrees Cent. \n&amp;quot;, temp.val1, temp.val2);&lt;br /&gt; printk(&amp;quot;Environmental Pressure: %d.%02d Bar \n&amp;quot;, press.val1, press.val2);&lt;br /&gt; printk(&amp;quot;Environmental Humidity: %d.%02d per/cent \n&amp;quot;, humidity.val1, humidity.val2);&lt;/p&gt;
&lt;p&gt;}&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;```&lt;/p&gt;
&lt;p&gt;Any comments pls?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI Master chip select in .overlay</title><link>https://devzone.nordicsemi.com/thread/289676?ContentTypeID=1</link><pubDate>Mon, 18 Jan 2021 10:35:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66300c86-aa00-4522-9d7a-f6fb00620219</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Add a file nrf9160d_nrf9160ns.overlay in zephyr\samples\sensor\bme280\boards with the following content:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi3 {
    status = &amp;quot;okay&amp;quot;;
    sck-pin = &amp;lt;10&amp;gt;;
    mosi-pin = &amp;lt;11&amp;gt;;
    miso-pin = &amp;lt;12&amp;gt;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 13 GPIO_ACTIVE_LOW&amp;gt;;
  
    bme280@0 {
      compatible = &amp;quot;bosch,bme280&amp;quot;;
      reg = &amp;lt;0x00&amp;gt;;
      //reg = &amp;lt;0x76&amp;gt;;
      spi-max-frequency = &amp;lt;4000000&amp;gt;;
      label = &amp;quot;BME280&amp;quot;;
    };
  };
  
  &amp;amp;uart3 {
    status = &amp;quot;disabled&amp;quot;;
  };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In addition, set&amp;nbsp;zephyr\samples\sensor\bme280\prj.conf to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SPI=y
CONFIG_I2C=n
CONFIG_SENSOR=y
CONFIG_BME280=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I was able to build the bme280 successfully with these modifications. I have not tested it, since I don&amp;#39;t have a BME280 at hand at the moment.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;Some explanations:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When using SPI, the field bme280@&lt;span&gt;{&lt;/span&gt;&lt;strong&gt;this field}&lt;/strong&gt;&amp;nbsp;(and reg = &amp;lt;{&lt;strong&gt;this field}&lt;/strong&gt;&amp;gt;)has a different meaning. In I2C, you initiate communication with a device by sending the address on the line, while in SPI you enable the CS line for the particular device. Then it doesn&amp;#39;t make sense to use the address 0x76 or&amp;nbsp;&lt;span&gt;13 in the dts, instead the field represent the chip select line number. These lines from &lt;a href="https://docs.zephyrproject.org/latest/guides/dts/intro.html#important-properties"&gt;DTS Guide --&amp;gt; Important properties&lt;/a&gt;&amp;nbsp;sums it up nicely:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1280x800/__key/communityserver-discussions-components-files/4/5074.pastedimage1610965902309v1.png" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you only add one SPI based sensor inside an spi node, you can use use the value 0, however if you add more devices do it like it&amp;#39;s done in&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/6104acba836eede58aec0d4ffe856307d0991763/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L136-L150"&gt;nrf/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The amount of inputs given to&amp;nbsp;cs-gpios in the SPI node&amp;nbsp;has to correspond to the amount of sub-devices.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>