<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I2C: delay required between setting RSTA and write to D? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645761#M39161</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a required delay between setting a repeat start condition and writing to the D register?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason I'm asking is because I have code that is misbehaving. After a repeated start, the next address byte gets mangled unless I insert a delay loop before writing to the D register.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm additionally puzzled because this is code that I used successfully before. I am now running it on a KL03 and testing on a FRDM-KL03Z board.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the attached scope screenshots. One shows a correct I2C sequence: W: 3A 0D, repeat start, R: 3B 1A. The other shows what happens if I remove the little delay: after a repeat start condition the next address byte gets transmitted as 0x0d (incidentally 0x0d is the previous byte that was transmitted before setting RSTA).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/3433iCB4AAAE79138C127/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png" alt="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/3473iC200BBFA67AC6C8E/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png" alt="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the full code and the line where the delay needs to be inserted: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2Fjwr%2Fkinetis_i2c%2Fblob%2Fmaster%2Fi2c.c%23L207" rel="nofollow" target="_blank"&gt;https://github.com/jwr/kinetis_i2c/blob/master/i2c.c#L207&lt;/A&gt;&lt;SPAN&gt; (e.g. just before line 207, the write to the D register).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found experimentally that a loop like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;for(delay_counter=0; delay_counter &amp;lt; 18; delay_counter++) {&lt;BR /&gt; __asm("NOP");&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;will fix the problem. Smaller number of iterations does not fix the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running with the default clocks and mult=2, icr=0x17, in case it matters (to get about ~50kHz I2C), but different speeds don't seem to change much. Also, the workaround for issue 6070 (errata for mask 1N96F) doesn't help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Oct 2016 08:52:36 GMT</pubDate>
    <dc:creator>jrychter</dc:creator>
    <dc:date>2016-10-18T08:52:36Z</dc:date>
    <item>
      <title>I2C: delay required between setting RSTA and write to D?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645761#M39161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a required delay between setting a repeat start condition and writing to the D register?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reason I'm asking is because I have code that is misbehaving. After a repeated start, the next address byte gets mangled unless I insert a delay loop before writing to the D register.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm additionally puzzled because this is code that I used successfully before. I am now running it on a KL03 and testing on a FRDM-KL03Z board.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the attached scope screenshots. One shows a correct I2C sequence: W: 3A 0D, repeat start, R: 3B 1A. The other shows what happens if I remove the little delay: after a repeat start condition the next address byte gets transmitted as 0x0d (incidentally 0x0d is the previous byte that was transmitted before setting RSTA).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/3433iCB4AAAE79138C127/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png" alt="DS1054Z_DS1ZA171205497_2016-10-17_17.40.29.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/3473iC200BBFA67AC6C8E/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png" alt="DS1054Z_DS1ZA171205497_2016-10-17_13.27.40 nodelay.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the full code and the line where the delay needs to be inserted: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2Fjwr%2Fkinetis_i2c%2Fblob%2Fmaster%2Fi2c.c%23L207" rel="nofollow" target="_blank"&gt;https://github.com/jwr/kinetis_i2c/blob/master/i2c.c#L207&lt;/A&gt;&lt;SPAN&gt; (e.g. just before line 207, the write to the D register).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found experimentally that a loop like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;for(delay_counter=0; delay_counter &amp;lt; 18; delay_counter++) {&lt;BR /&gt; __asm("NOP");&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;will fix the problem. Smaller number of iterations does not fix the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running with the default clocks and mult=2, icr=0x17, in case it matters (to get about ~50kHz I2C), but different speeds don't seem to change much. Also, the workaround for issue 6070 (errata for mask 1N96F) doesn't help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Oct 2016 08:52:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645761#M39161</guid>
      <dc:creator>jrychter</dc:creator>
      <dc:date>2016-10-18T08:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: I2C: delay required between setting RSTA and write to D?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645762#M39162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This sounds like the Double Buffered IIC issue which has been discussed on this forum at some length.&lt;/P&gt;&lt;P&gt;See&lt;/P&gt;&lt;H1&gt;Double Buffered I2C Difficulties (eg. KL27)&lt;/H1&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Martin.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Oct 2016 09:22:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645762#M39162</guid>
      <dc:creator>Xlerb</dc:creator>
      <dc:date>2016-10-18T09:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: I2C: delay required between setting RSTA and write to D?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645763#M39163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow, I didn't even notice the I2C peripheral in the KL03 is different from the ones I've used before! I developed and used the code on KL05, KL25 and K20. This is so frustrating. I thought the whole point of sticking with stone-age peripherals that we see in the Kinetis line was that they are well known back from older 8-bit micros, are reliable, predictable and well-documented. And then we get this kind of thing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess it's my fault for not carefully checking that the I2C isn't quite the same I2C anymore, but where do I look for things like that? I never expected that switching from KL05 to KL03 would mean my I2C code will stop working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A quick look seems to indicate that I will have to implement a workaround so that repeated start works again. I wonder how to make the driver universal — will have to detect somehow the different I2C peripherals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for answering — I've spent far too much time on this already, now at least I know what the problem is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Oct 2016 11:59:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645763#M39163</guid>
      <dc:creator>jrychter</dc:creator>
      <dc:date>2016-10-18T11:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: I2C: delay required between setting RSTA and write to D?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645764#M39164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Has you've discerned the 'Good old days' are gone. &amp;nbsp;Broken parts, poor documentation, no official acknowledgments of the double buffered I2C problems with an easy to find Erata (Been a year last week since the problem was reported!) etc. &amp;nbsp;You are just the most recent documented victim of Double Buffering Bug :-(&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now for something more productive:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;for(delay_counter=0; delay_counter &amp;lt; 18; delay_counter++) {&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #f6f6f6;" /&gt;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;__asm("NOP");&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #f6f6f6;" /&gt;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The nop needs to be marked &amp;nbsp;'volatile':&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm__ __volatile__ ("nop");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise the compiler optimizer may remove it as it has no side effects.&lt;/P&gt;&lt;P&gt;Turn off optimization is not the correct solution, as some have done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also depending on the exact ARM part a nop may not actually consume any time.&lt;/P&gt;&lt;P&gt;It could be removed from the pipeline before execution.&lt;/P&gt;&lt;P&gt;In reality it is the for loop itself consuming the time in some cases.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 14:21:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-delay-required-between-setting-RSTA-and-write-to-D/m-p/645764#M39164</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2016-10-19T14:21:11Z</dc:date>
    </item>
  </channel>
</rss>

