<?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 Re: I2C+KSDK+PE+Interrupt Problem in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455892#M27173</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jorge Gonzales,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That works! But, I like to know if &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;"I2C_DRV_MasterGetReceiveStatus " and "I2C_DRV_MasterGetSendStatus" are really bugged, to not use them again!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Im doing this driver to use RTOS, so the &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;flag i2c_handler.i2cTransactionFinished is in fact a semaphore! Thats why I dont &lt;/SPAN&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;poll the flag i2c_0_MasterState.i2cIdle.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Nov 2015 12:27:21 GMT</pubDate>
    <dc:creator>matheuspinto</dc:creator>
    <dc:date>2015-11-13T12:27:21Z</dc:date>
    <item>
      <title>I2C+KSDK+PE+Interrupt Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455890#M27171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to get help from the community for the problem indicated in this thread:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-thread-small" data-containerid="11234" data-containertype="14" data-objectid="372948" data-objecttype="1" href="https://community.freescale.com/thread/372948"&gt;https://community.freescale.com/thread/372948&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I got no answer. Thus, now I will use an example of a simple program without RTOS.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached are two projects. One of them works properly and the other don't. To both, I'm using the FRDM-KL25Z with KDS 3.0 + KSDK + PE.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal of the project is communication with the accelerometer, built into the board, through the I2C. For the test, its used the RGB LED in the board, where the light (blue, green or red) corresponding to the axis rises when it is in parallel with the vertical.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The project that works fine is the "i2c_sdk_test". In this project, the module " i2c_gen_driver" implement an i2c driver, that uses the KSDK. The writing functions are " i2c_MasterRead" and " i2c_MasterWrite". Their codes can be seen in Figures below.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96883_96883.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120763i8C99AA5375829B7C/image-size/large?v=v2&amp;amp;px=999" role="button" title="96883_96883.png" alt="96883_96883.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21842i9E1F22F651CF1DD7/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.png" alt="pastedImage_4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96884_96884.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120764iC09556CA6FCAEE9C/image-size/large?v=v2&amp;amp;px=999" role="button" title="96884_96884.png" alt="96884_96884.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_5.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21788i48C521F61D402233/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_5.png" alt="pastedImage_5.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As can be seen, after every read or write by KSDK API, is made a pooling that verifies if the bus is not busy.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the other project, the "i2c_sdk_test_with_flag" I want to warning the writing/reading functions when the bus is not busy, with a flag in I2C ISR. For this, I created a global flag in the file "i2c_gen_driver.c" as shown in the figure below.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96885_96885.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120765i83D693682BC67179/image-size/large?v=v2&amp;amp;px=999" role="button" title="96885_96885.png" alt="96885_96885.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_18.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21843iD9BF08C5B27237E6/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_18.png" alt="pastedImage_18.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ISR code, within " i2c_gen_driver.c" is divided into two parts, as seen in the figure below: a test for the direction of communication; and another that verifies if the I2C communication came to an end, by setting the flag.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96886_96886.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120766i64C80ACCEBCBCC7C/image-size/large?v=v2&amp;amp;px=999" role="button" title="96886_96886.png" alt="96886_96886.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_28.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/161i4DD4412CD6A6ED1B/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_28.png" alt="pastedImage_28.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now, after every read or write by KSDK API is evaluated if the flag was set, before proceeding. As shown in the figure below.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96887_96887.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120767iF228E267FF69CB6C/image-size/large?v=v2&amp;amp;px=999" role="button" title="96887_96887.png" alt="96887_96887.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_43.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21947i23798A752A324F5F/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_43.png" alt="pastedImage_43.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, the code doesn’t work as expected, the RGB LED don’t light properly.&lt;/P&gt;&lt;P&gt;I thought that KSDK API, "I2C_DRV_MasterGetReceiveStatus " and "I2C_DRV_MasterGetSendStatus", was returning an incorrect value status within the ISR.&lt;/P&gt;&lt;P&gt;Then as shown in the figure below, I added a code after the flag test in reading and writing functions to see if the bus was not busy, in fact.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96888_96888.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120768i04AC7F4C8414E6E2/image-size/large?v=v2&amp;amp;px=999" role="button" title="96888_96888.png" alt="96888_96888.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_49.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21993iD680494AD5529C11/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_49.png" alt="pastedImage_49.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in debug it was confirmed what I thought, as shown in Figure below. The flag is set in the ISR indicating that the bus is not busy, however when the program return to the write/read function, the status function indicates that the bus is busy.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="96889_96889.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/120769i59DE5E5CD4FAECD2/image-size/large?v=v2&amp;amp;px=999" role="button" title="96889_96889.png" alt="96889_96889.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_65.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/266iB503834BE5D5A141/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_65.png" alt="pastedImage_65.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "I2C_DRV_MasterGetReceiveStatus" and "I2C_DRV_MasterGetSendStatus" functions don’t work properly within ISRs?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337402"&gt;i2c_sdk_test_with_flag.rar&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337402"&gt;i2c_sdk_test.rar&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Nov 2015 20:27:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455890#M27171</guid>
      <dc:creator>matheuspinto</dc:creator>
      <dc:date>2015-11-04T20:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: I2C+KSDK+PE+Interrupt Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455891#M27172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Matheus Pinto:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I analyzed your issue and I think there is a bug in the driver or maybe a misunderstanding of the same, but I will report it to the developers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The driver sets the &lt;STRONG&gt;master-&amp;gt;status&lt;/STRONG&gt; to &lt;STRONG&gt;&lt;EM&gt;kStatus_I2C_Success&lt;/EM&gt; &lt;/STRONG&gt;immediately after sending the slave address, so when you are checking the Send or Receive status in the interrupt context and receive a SUCCESS, not all data has been actually sent or received.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As workaround you could use this code in your ISR:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14470454305985791" data-renderedposition="197.4499969482422_8_1129_208" jivemacro_uid="_14470454305985791"&gt;&lt;P&gt;//the ISR from i2c interrupts&lt;/P&gt;&lt;P&gt;void I2C0_IRQHandler(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t bytesRemaining;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c_status_t i2cReturn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I2C_DRV_IRQHandler(FSL_I2C_0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // Check if the I2C transfer is completed&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(i2c_0_MasterState.i2cIdle)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c_handler.i2cTransactionFinished = true;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or you could simply poll the flag &lt;STRONG&gt;i2c_0_MasterState.i2cIdle&lt;/STRONG&gt; in your application instead of your flag &lt;STRONG&gt;i2c_handler.i2cTransactionFinished&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards!,&lt;BR /&gt;Jorge Gonzalez&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Nov 2015 05:03:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455891#M27172</guid>
      <dc:creator>Jorge_Gonzalez</dc:creator>
      <dc:date>2015-11-09T05:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: I2C+KSDK+PE+Interrupt Problem</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455892#M27173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jorge Gonzales,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That works! But, I like to know if &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;"I2C_DRV_MasterGetReceiveStatus " and "I2C_DRV_MasterGetSendStatus" are really bugged, to not use them again!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Im doing this driver to use RTOS, so the &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;flag i2c_handler.i2cTransactionFinished is in fact a semaphore! Thats why I dont &lt;/SPAN&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;poll the flag i2c_0_MasterState.i2cIdle.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2015 12:27:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-KSDK-PE-Interrupt-Problem/m-p/455892#M27173</guid>
      <dc:creator>matheuspinto</dc:creator>
      <dc:date>2015-11-13T12:27:21Z</dc:date>
    </item>
  </channel>
</rss>

