<?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>TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62194/twi-optimization-issue</link><description>Hello! This is my first time using a Nordic product and I&amp;#39;m still learning the basics. I am adapting the TWI Sensor example and I&amp;#39;m trying to read data back from an accelerometer. Unfortunately, it&amp;#39;s jumping out of a function before it should (and running</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 Jun 2020 14:42:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62194/twi-optimization-issue" /><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/254306?ContentTypeID=1</link><pubDate>Wed, 10 Jun 2020 14:42:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7969a253-4f47-48b3-801a-7e7e3afa7ee0</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;This is a compiler-specific question that you should direct to the developers of the compilers/IDE you are using. Modified source files should be rebuilt when changes are detected, I would expect this to be the case with modified dependency header files as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/253878?ContentTypeID=1</link><pubDate>Mon, 08 Jun 2020 16:45:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e825411a-62ec-4aaf-ac34-80cda2a8a3b8</guid><dc:creator>JayDev</dc:creator><description>&lt;p&gt;Ok, I confirmed that it now appears to work, even at optimization level 2, so all this could be an issue with the project needing to be cleaned between builds?&amp;nbsp; &lt;br /&gt;&lt;br /&gt;Can you explain what exactly is being built between projects when I click build?&amp;nbsp; It appears that it&amp;#39;s not actually building enough to properly represent the code, if I follow this correctly.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/253877?ContentTypeID=1</link><pubDate>Mon, 08 Jun 2020 16:42:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0162f0d-68b5-4c7e-9822-ab82de2e6a7b</guid><dc:creator>JayDev</dc:creator><description>&lt;p&gt;I might&amp;#39;ve figured out the issue.&amp;nbsp; I ended up stepping through the project and it went to the true statement.&amp;nbsp; I guess something wasn&amp;#39;t cleaned up between builds?&amp;nbsp; Sounds like I might need to clean between every build, if I&amp;#39;m interpreting this correctly.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/253874?ContentTypeID=1</link><pubDate>Mon, 08 Jun 2020 16:26:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0e1a35b-3953-4166-a347-0bacf97e2cd9</guid><dc:creator>JayDev</dc:creator><description>&lt;p&gt;In hindsight, it makes sense it would optimize it out if the only answer it ever returns is false, regardless of whether both sides match or not.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/253873?ContentTypeID=1</link><pubDate>Mon, 08 Jun 2020 16:24:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cdc5d6f-3436-46e5-92e9-bd87bca1df13</guid><dc:creator>JayDev</dc:creator><description>&lt;p&gt;Hmm, it looks like that was indeed the issue.&amp;nbsp; I&amp;#39;m kind of surprised the check would be optimized out.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;I do have a related question though.&amp;nbsp; It has to do with this section of the code:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(m_sample==WHO_AM_I_RESPONSE)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;So, my &amp;quot;WHO_AM_I_RESPONSE&amp;quot; is setup as:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define WHO_AM_I_RESPONSE&amp;nbsp;&amp;nbsp; 0x1D&lt;/p&gt;
&lt;p&gt;I can confirm that my m_sample is being returned as a uint8_t with a value of 0x1D.&amp;nbsp; When I&amp;#39;m comparing those, I&amp;#39;m finding the value of the who am I response is something like 0x0000000000000000000001D or something along those lines.&amp;nbsp; To resolve this issue, I cast my #define variable so that now my code looks like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(m_sample==(uint8_t)WHO_AM_I_RESPONSE)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I can hover over m_sample and see the value is 0x1d and do the same with the cast variable of the who am I response (which also provides 0x1d) but find that it still returns false.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I decided to change the who am I response from a #define to:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t WHO_AM_I_RESPONSE = 0x1d;&lt;/p&gt;
&lt;p&gt;in case the issue is related to comparing a #define (even if it&amp;#39;s cast properly) to a declared variable but still got the same issue.&amp;nbsp; Then I cast m_sample to a uint8_t (just in case).&amp;nbsp; That ALSO failed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So now, I&amp;#39;m changing my optimization setting from 0 to none and still no luck.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there something wrong with my if statement that I&amp;#39;m not seeing?&amp;nbsp; If both sides are 0x1d, I don&amp;#39;t see how it&amp;#39;s possible to be returning false in any of these cases.&amp;nbsp; Any help you can give me would be greatly appreciated!&amp;nbsp; Thanks!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Optimization Issue?</title><link>https://devzone.nordicsemi.com/thread/253540?ContentTypeID=1</link><pubDate>Fri, 05 Jun 2020 12:41:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67c568d2-ea7a-4a72-9cbe-bfd878312b74</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If the compiler has decided that the outcome of the error checking is known at compile-time, the instructions may be optimized away. If there are no operations at the line, there is no place for the debugger to break. You can reduce/disable the optimization level in the project options. If you want check the error code, you can print it using NRF_LOG or similar.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>