<?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>NRF52840 I2C INTERFACE WITH BMP280</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93780/nrf52840-i2c-interface-with-bmp280</link><description>Hi everybody, 
 
 I am trying my best to make my nrf52840dk communicating with an external bmp280 sensor using i2c, but I could not even read the cip id. 
 
 Maybe I completely misunderstood how to do it. 
 
 Here&amp;#39;s my prj.conf : 
 
 CONFIG_I2C = y 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Nov 2022 14:20:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93780/nrf52840-i2c-interface-with-bmp280" /><item><title>RE: NRF52840 I2C INTERFACE WITH BMP280</title><link>https://devzone.nordicsemi.com/thread/396015?ContentTypeID=1</link><pubDate>Wed, 16 Nov 2022 14:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79341176-7e71-4df7-8076-d3bd4ad8f0c5</guid><dc:creator>MarkusK</dc:creator><description>&lt;p&gt;Hi Gianmarco,&lt;/p&gt;
&lt;p&gt;if you are using the driver you have to define an overlay file with a child node, since you get the device from the command&amp;nbsp; DEVICE_DT_GET_ANY(bosch_bmp280) and there is the I2C-Adress stored.&lt;/p&gt;
&lt;p&gt;I think you mean if you are use an i2c device and not&amp;nbsp; i2c_dt_spec. There you dont need to define an bmp-node.&lt;/p&gt;
&lt;p&gt;Its depends on the use case what model its better to use. The driver is in a lot cases a good choice. But the sensor needs also to be connected at the power up from the SoC. And sometimes the driver is just overloaded when you need only specific things. Sometimes it&amp;#39;s also more easy to use special functionalities from one sensor when you configure it directly over i2c.&lt;/p&gt;
&lt;p&gt;Regards&lt;br /&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C INTERFACE WITH BMP280</title><link>https://devzone.nordicsemi.com/thread/395442?ContentTypeID=1</link><pubDate>Sun, 13 Nov 2022 17:55:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4df6cbf2-81d7-4f4e-ae75-c2f2719ccaef</guid><dc:creator>gianmarcod</dc:creator><description>&lt;p&gt;Hi Markus,&lt;/p&gt;
&lt;p&gt;Sorry for my delayed response.&lt;/p&gt;
&lt;p&gt;I tried to run the code you suggested but it didn&amp;#39;t work. But actually the main problem was a bad soldering of the connectors which prevented electrical communications between the dk and the sensor.&lt;/p&gt;
&lt;p&gt;Soldering a new device and flashing your code, I finally managed to communicate with my sensor!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I attach here a working application that may helps other interested users:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;prj.confg:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;CONFIG_I2C=y&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;nrf52840dk_nrf52840.overlay:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;amp;i2c0 {&lt;br /&gt;&amp;nbsp; &amp;nbsp;bmp280: bmp280@76{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; compatible = &amp;quot;bosch,bmp280&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; reg = &amp;lt;0x76&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; label = &amp;quot;BOSCH_BMP280_SENSOR&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;};&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;main.c&lt;/strong&gt;:&lt;/span&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;sys/printk.h&amp;gt;&lt;br /&gt;#include &amp;lt;drivers/i2c.h&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;#define BMP_REG_ID 0xD0&lt;/p&gt;
&lt;p&gt;#define BMP280_NODE DT_NODELABEL(bmp280)&lt;/p&gt;
&lt;p&gt;void main(void)&lt;br /&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(BMP280_NODE);&lt;br /&gt;&amp;nbsp; &amp;nbsp;if (!device_is_ready(dev_i2c.bus)) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; printk(&amp;quot;I2C bus %s is not ready!\n\r&amp;quot;,dev_i2c.bus-&amp;gt;name);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;uint8_t read_buf_id[1];&lt;br /&gt;&amp;nbsp; &amp;nbsp;uint8_t write_reg_buffer[1];&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;write_reg_buffer[0] = BMP_REG_ID;&lt;br /&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp;printf(&amp;quot;writing %x to the device\n&amp;quot;, write_reg_buffer[0]);&lt;br /&gt;&amp;nbsp; &amp;nbsp;int err = i2c_write_read_dt(&amp;amp;dev_i2c, write_reg_buffer, 1, read_buf_id, 1);&lt;br /&gt;&amp;nbsp; &amp;nbsp;if(err &amp;lt; 0){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; printk(&amp;quot;BMP CHIP ID read failed: %d\n&amp;quot;, err); &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;br /&gt;&amp;nbsp; &amp;nbsp;} &lt;br /&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp;printf(&amp;quot;reading %x from the device\n&amp;quot;, read_buf_id[0]);&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;while (1) { }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As for your second observation. Let me say that I used the i2c-bus because I was kinda desperated. I tried to use the driver as well as I feel more confident with that, and it worked.&lt;/p&gt;
&lt;p&gt;I noticed that, using the driver, it is not even necessary to define the bmp280 as a child node of the i2c node. It is enough to send commands over i2c specifyng the address of the slave device directly in the write, read, write/read command. Is it true?&lt;/p&gt;
&lt;p&gt;I mean, using the driver model I left my overlay file empty.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which model would you suggest me to use? bus or driver?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Gianmarco&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C INTERFACE WITH BMP280</title><link>https://devzone.nordicsemi.com/thread/395304?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 12:22:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c52fb885-39a7-4a0f-93b6-bac7eeba52e2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;It may also be a good idea to enable logging (CONFIG_LOG=y) to see if you get any error messages from the TWIM driver.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C INTERFACE WITH BMP280</title><link>https://devzone.nordicsemi.com/thread/395218?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 02:23:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30a65efc-327d-41b2-9cf1-c0bee3f1d8e7</guid><dc:creator>MarkusK</dc:creator><description>&lt;p&gt;Hi Gianmarco,&lt;/p&gt;
&lt;p&gt;Maybe you try this:&lt;br /&gt;&lt;br /&gt;#define BMP280_REG_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xD0&lt;br /&gt;&lt;br /&gt;uint8_t read_buf_id[1];&lt;br /&gt;uint8_t write_reg_buffer[1];&lt;br /&gt;&lt;br /&gt;// Read chip ID&lt;br /&gt;write_reg_buffer[0]=BMP280_REG_ID;&lt;br /&gt;err = i2c_write_read_dt(dev_i2c, write_reg_buffer, 1, read_buf_id, 1);&lt;br /&gt;if (err &amp;lt; 0){ printk(&amp;quot;BMP CHIP ID read failed: %d\n&amp;quot;, err); return; }&lt;br /&gt;&lt;br /&gt;If its still not working maybe take a look at the video &amp;quot;Zephyr and Nordic nRF Connect SDK - 03b Temperature, pressure and humidity from a Bosch BME280&amp;quot;&lt;br /&gt;&lt;a href="https://www.youtube.com/watch?v=prZomlfA_bI"&gt;www.youtube.com/watch&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The BME280 works the same except it has also humidity. To check if the sensor is working you can also use the driver instead using the I2C-Bus.&lt;br /&gt;&lt;br /&gt;Regards &lt;br /&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>