<?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>I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119888/i2c-functions-don-t-work-but-using-the-i2c-shell-does</link><description>I bought a tiny board on Aliexpress from HolyIOT. It comes with an nRF52832 and an LIS2DH12 accelerometer. The silkscreen on the board says HOLYIOT-21011-v1.0. 
 This schematic is not from the exact same board but is nearly identical. Sorry for the bad</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Aug 2025 19:41:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119888/i2c-functions-don-t-work-but-using-the-i2c-shell-does" /><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/545270?ContentTypeID=1</link><pubDate>Mon, 11 Aug 2025 19:41:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4650b82-ebc3-4f73-9006-3f8ae42a191e</guid><dc:creator>j_a536</dc:creator><description>&lt;p&gt;Sorry for the late reply. I couldn&amp;#39;t compile your sample, so I wasn&amp;rsquo;t able to test it. But don&amp;rsquo;t worry, I tried doing the same using Rust to rule out any issue related to NCS. This way, I discovered that scanning I2C devices before trying to communicate with the sensor did the trick (Yes, it seems like a hardware-related issue.). So, back in NCS, I added &lt;strong&gt;&lt;code data-start="382" data-end="405"&gt;zephyr,deferred-init;&lt;/code&gt;&lt;/strong&gt; in the devicetree:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;i2c1 {
	status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;i2c1_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;i2c1_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;

	lis2dh: lis2dh@19 {
    status = &amp;quot;okay&amp;quot;;
		compatible = &amp;quot;st,lis2dh&amp;quot;;
		reg = &amp;lt;0x19&amp;gt;;
		irq-gpios = &amp;lt;&amp;amp;gpio0 6 GPIO_ACTIVE_HIGH&amp;gt;,  &amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_HIGH&amp;gt;;
		zephyr,deferred-init;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I2C devices scan and sensor intialization:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const struct device *dev = device_get_binding(&amp;quot;i2c@40004000&amp;quot;);

if (dev == NULL) {
  printk(&amp;quot;No device found\n&amp;quot;);
  return;
}

for (uint8_t addr = 0x03; addr &amp;lt;= 0x77; addr++) { //scan this range is sufficient
  struct i2c_msg msg;
  uint8_t dummy;

  msg.buf = &amp;amp;dummy;
  msg.len = 1;
  msg.flags = I2C_MSG_WRITE | I2C_MSG_STOP;

  int ret = i2c_transfer(dev, &amp;amp;msg, 1, addr);

  if (ret == 0) {
    printk(&amp;quot;Device found at 0x%02x\n&amp;quot;, addr);
  }
}

device_init(sensor);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/530371?ContentTypeID=1</link><pubDate>Thu, 03 Apr 2025 07:31:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88430215-6561-4f65-99e0-45b3a9d44048</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;So you didn&amp;#39;t get it working with the sample that I sent?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What analyzer did you use? Does it power the chip? Or is it only the thin cables shown in the picture (purple and orange) for SDA and SCL?&lt;/p&gt;
&lt;p&gt;So it doesn&amp;#39;t work when you have the RTT log connected but the analyzer disconnected?&lt;/p&gt;
&lt;p&gt;What comes to mind is that perhaps your analyzer adds some pull configuration. Do you have the pull-up configuration on i2c1_default?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	i2c1_default: i2c1_default {
		group1 {
			psels = &amp;lt;NRF_PSEL(TWIM_SDA, 0, 2)&amp;gt;,
							&amp;lt;NRF_PSEL(TWIM_SCL, 0, 24)&amp;gt;;
							bias-pull-up;
		};
	};
	
	i2c1_sleep: i2c1_sleep {
		group1 {
			psels = &amp;lt;NRF_PSEL(TWIM_SDA, 0, 2)&amp;gt;,
							&amp;lt;NRF_PSEL(TWIM_SCL, 0, 24)&amp;gt;;
							low-power-enable;
		};
	};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/530322?ContentTypeID=1</link><pubDate>Wed, 02 Apr 2025 19:40:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efd870c4-8c6e-4826-86f9-f123afac9f56</guid><dc:creator>j_a536</dc:creator><description>&lt;p&gt;Thanks for your help.&lt;/p&gt;
&lt;p&gt;Finally, it was necessary to connect to the I2C lines to observe what was really happening (it seemed impossible). I was greatly surprised when I tried using the official sensor driver again (just as I had initially attempted) and saw that it worked perfectly fine. I confirmed this both with the logic analyzer and through the RTT logs.&lt;/p&gt;
&lt;p&gt;However, when disconnecting the analyzer (from the computer, i.e., its power&amp;nbsp;supply, not the probes from the I2C lines), the microcontroller was once again unable to communicate with the sensor. Yet, it still worked when testing communication from the I2C shell.&lt;/p&gt;
&lt;p&gt;This brings me back to my initial question. It seems clear that there is a hardware issue (which I did not design and cannot modify), but the communication works with the shell and not with the sensor driver. So, I don&amp;rsquo;t understand this inconsistency.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/1743622599739.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/528818?ContentTypeID=1</link><pubDate>Tue, 25 Mar 2025 11:29:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce3ce5a1-5e40-4c96-bf2a-ed543d3bcebf</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;By the way, that solution is not optimal. I ended up with two devicetree instances in your tilt.c, because one was used to fetch the device i2c address, while the other was used to initialize it. I recommend that you check out the devAcademy course: NCS Fundamentals, which has a lesson on I2C in NCS:&lt;/p&gt;
&lt;p&gt;Lesson 6 covers I2C:&lt;br /&gt;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-6-serial-com-i2c/topic/exercise-1-6-2/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-6-serial-com-i2c/topic/exercise-1-6-2/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/528811?ContentTypeID=1</link><pubDate>Tue, 25 Mar 2025 11:09:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a65c214-a778-4106-81d8-262e9751c345</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/AccSensor_5F00_suggestion.zip"&gt;devzone.nordicsemi.com/.../AccSensor_5F00_suggestion.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. I got something working on my end, but it was with a different sensor, so you need to modify it a bit. I made it just read the &amp;quot;WHO_AM_I&amp;quot; register, which on the mpu6050 is the 0x75 register address. I also added an .overlay file in your application folder, where I did some modifications. This will overwrite whatever is in the board files, so go through them and see if you want to revert something. For instance, I changed the LEDs to match the LED pins on the nRF52832 DK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also changed the I2C pins in the overlay file, so you can change it back from 24 to 5. I tested it now (after I zipped it), and it still works.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/528082?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 19:25:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc9e37bc-41be-4d7b-a3fb-2f99e07c7608</guid><dc:creator>j_a536</dc:creator><description>&lt;p&gt;I&amp;#39;m using NCS version 2.8.0, with a custom board based on the nRF52832 (included in the boards directory) as the target, and incorporating the sensor and other modifications according to the schematic.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/config_5F00_ncs.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/527997?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 11:49:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20a2de38-8968-405f-bb5b-5515b12490ab</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;What NCS version are you using, and what is your build command? Particularly, what board are you building for?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/527864?ContentTypeID=1</link><pubDate>Tue, 18 Mar 2025 14:07:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:444a0d7e-870a-4f7a-b073-f1a59c455715</guid><dc:creator>j_a536</dc:creator><description>&lt;p&gt;Thank you for your help! I&amp;rsquo;ve attached the zip file. I also forgot to mention that I&amp;rsquo;m unable to probe the lines due to their small size and the lack of test points :(&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/AccSensor_5F00_simplified.zip"&gt;devzone.nordicsemi.com/.../AccSensor_5F00_simplified.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C functions don’t work, but using the I2C shell does</title><link>https://devzone.nordicsemi.com/thread/527753?ContentTypeID=1</link><pubDate>Tue, 18 Mar 2025 07:12:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c006fe08-49ff-4f48-ba4c-f6149fade0d2</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Is it possible to zip and upload the application that you are testing on? I don&amp;#39;t have that exact sensor, but I have some I2C things that I can test on with minor modifications.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>