<?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>Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102356/using-i2c-on-nrf52840-with-2-sensor-devices</link><description>I want to get sensor data from the Bosch BNO055 and the NXP MPR121 to the nRF52840 (DK, for now) using I2C. I completed the Nordic Connect SDK Fundamentals course, and am trying to adapt Lesson 6 Exercise 1 to be for two sensors; however, if I try to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Aug 2023 18:17:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102356/using-i2c-on-nrf52840-with-2-sensor-devices" /><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/439775?ContentTypeID=1</link><pubDate>Thu, 03 Aug 2023 18:17:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3adef11-1b84-42f7-abad-8a0d658b8574</guid><dc:creator>swood</dc:creator><description>&lt;p&gt;Thank you all! It worked, some weird quirky things I figured out on my end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/439062?ContentTypeID=1</link><pubDate>Mon, 31 Jul 2023 13:59:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1e076be-4416-4cc1-b90f-a9c4511768ae</guid><dc:creator>khelmutlord</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You are correct. The orthodox way to add a device driver to Zephyr is to create an out-of-tree driver and fill in all of the boilerplate (kconfigs, etc). For early stages of development it is simpler to use the generic I2C device to at least get communicating. You can continue to use the generic device or you could create device tree bindings, relevant Kconfigs, and a driver implementation and upstream it into Zephyr itself.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you share&amp;nbsp;your build log when you run a pristine build? Sometimes errors will persist in devicetree files until a pristine build.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, the data type you use should be &amp;quot;i2c_dt_spec&amp;quot; right now you are treating it as though it were a variable name. There is a typedef for the struct &amp;quot;i2c_dt_spec&amp;quot; so your lines should be:&lt;/p&gt;
&lt;p&gt;static const struct i2c_dt_spec dev0_i2c...&lt;/p&gt;
&lt;p&gt;instead of&lt;/p&gt;
&lt;p&gt;static const struct i2c_dt_spec&lt;em&gt;&lt;strong&gt;0&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;dev0_i2c...&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Helmut Lord&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/439030?ContentTypeID=1</link><pubDate>Mon, 31 Jul 2023 13:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d81e8621-66b5-4c3f-b2aa-750f87ad02c2</guid><dc:creator>swood</dc:creator><description>&lt;p&gt;My sensors are not in the Zephyr bindings, and no info online that I could find--where do I go from there?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/439026?ContentTypeID=1</link><pubDate>Mon, 31 Jul 2023 13:05:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c7066b8-f202-40b8-b1a9-15ab0a5b0151</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;1) Yes, &amp;quot;I2c_device_0&amp;quot; over here is the name of the node and you can choose it as you like&lt;/p&gt;
&lt;p&gt;2) compatible=&amp;quot;vnd,i2-device&amp;quot; means that the specific i2c-device is from the specific vendor. Below, see a compatible property for BOSCH BME680 sensor (located at /zephyr/dts/bindings/sensor/)&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1690808474350v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;So when we want to add BOSCH BME680 sensor to the i2c bus, then we add this compatible entry in the overlay&lt;/p&gt;
&lt;p&gt;For your sensor, please see if it is available in the zephyr bindings or search online for help related to those sensors.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;3) We can get the node-label using the DT_NODELABEL() macro if everything is good/correct in the overlay, otherwise it should produce error as in your case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/438830?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2023 19:20:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8ea7aac-8b0f-4194-a2bc-2adb10683104</guid><dc:creator>swood</dc:creator><description>&lt;p&gt;I&amp;#39;ll look into the shell, thank you!&lt;/p&gt;
&lt;p&gt;As far as device configuration: 1) can the name &amp;quot;12c_device_0&amp;quot; be anything? 2) Does&amp;nbsp;&lt;span&gt;compatible&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;quot;vnd,i2c-device&amp;quot;&lt;/span&gt;&lt;span&gt;; have to change? Where did we get vnd? Right now, it is showing up as an &amp;quot;unknown type&amp;quot;, though it seems this is used for generic drivers.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;Adding the DT_NODELABEL call didn&amp;#39;t help my errors--I had called it earlier in the script. Still getting the same errors. Do you know what might be causing them? Is it just the missing driver files?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Is it Section 4 from&amp;nbsp;&lt;a id="" href="https://blog.golioth.io/how-to-use-generic-spi-devices-with-zephyr/"&gt;https://blog.golioth.io/how-to-use-generic-spi-devices-with-zephyr/&lt;/a&gt;&amp;nbsp;that is outlining what I need to do to get the right driver so my device will be recognized? I can&amp;#39;t tell what they&amp;#39;re creating and where they&amp;#39;re putting it. Could you offer any more advice? Once I make that file and put it somewhere, I&amp;#39;ll let you know if the errors go away.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using I2C on nRF52840 with 2 sensor devices</title><link>https://devzone.nordicsemi.com/thread/438803?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2023 15:51:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c509972-32ae-42f8-87e5-7f1ee605b4e4</guid><dc:creator>khelmutlord</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I would recommend adding the Kconfig &amp;quot;CONFIG_SHELL=y&amp;quot; and &amp;quot;CONFIG_I2C_SHELL=y&amp;quot; for your project especially when starting out. It will allow you to directly interact with I2C devices (i.e. scan to make sure addresses are correct, read ID registers).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://blog.golioth.io/how-to-use-zephyr-shell-for-interactive-prototyping-with-i2c-sensors/"&gt;blog.golioth.io/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For your devicetree configuration, try something like the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;amp;i2c0 {
    compatible = &amp;quot;nordic,nrf-twi&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
    pinctrl-0 = &amp;lt;&amp;amp;i2c0_default&amp;gt;;
    pinctrl-1 = &amp;lt;&amp;amp;i2c0_sleep&amp;gt;;
    pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
    i2c_device_0: i2cdev0@&amp;lt;FILL_IN_DEVICE_ADDR&amp;gt; {
        status = &amp;quot;okay&amp;quot;;
        compatible = &amp;quot;vnd,i2c-device&amp;quot;;
        reg = &amp;lt;FILL_IN_DEVICE_ADDR&amp;gt;;
    };
    i2c_device_1: i2cdev1@&amp;lt;FILL_IN_DEVICE_ADDR&amp;gt; {
        status = &amp;quot;okay&amp;quot;;
        compatible = &amp;quot;vnd,i2c-device&amp;quot;;
        reg = &amp;lt;FILL_IN_DEVICE_ADDR&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then, to access the devices, you can use:&lt;/p&gt;
&lt;p&gt;static const struct i2c_dt_spec0 dev0_i2c = I2C_DT_SPEC_GET(DT_NODELABEL(i2c_device_0));&lt;/p&gt;
&lt;p&gt;I think the reason you were getting errors was because you weren&amp;#39;t grabbing the node label.&lt;/p&gt;
&lt;p&gt;I checked through Zephyr and the two devices you are using don&amp;#39;t have in-tree Zephyr drivers. Not to worry! Here is a guide from a Nordic partner, Golioth, on creating&amp;nbsp;&lt;em&gt;&lt;/em&gt;generic&amp;nbsp;&lt;em&gt;SPI&lt;/em&gt; device drivers. Of course you are using I2C here but the general concepts are the same.&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://blog.golioth.io/how-to-use-generic-spi-devices-with-zephyr/"&gt;https://blog.golioth.io/how-to-use-generic-spi-devices-with-zephyr/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also check the Zephyr I2C docs.&amp;nbsp;&lt;a id="" href="https://docs.zephyrproject.org/latest/hardware/peripherals/i2c.html"&gt;https://docs.zephyrproject.org/latest/hardware/peripherals/i2c.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Be sure to skim through them. There are a lot of nice helper functions like &amp;quot;&lt;span&gt;i2c_reg_write_byte_dt&amp;quot; that do a lot of the setup for you depending on the operation you&amp;#39;re trying to do.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finally, you can refer to the Zephyr examples for I2C device drivers. This can make it a bit easier to see what setup steps you may need to take for your I2C device. For instance:&amp;nbsp;&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/tree/main/drivers/sensor/bme680"&gt;https://github.com/zephyrproject-rtos/zephyr/tree/main/drivers/sensor/bme680&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Helmut Lord&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>