<?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>Kinetis MicrocontrollersのトピックFRDM-K22F I2C Failure with sensor</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-I2C-Failure-with-sensor/m-p/687545#M42324</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a kinetis FRDM-F22 board connected to an LIS331H (&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fwww.sparkfun.com%2Fdatasheets%2FSensors%2FAccelerometer%2FLIS331HH.pdf" rel="nofollow" target="_blank"&gt;https://www.sparkfun.com/datasheets/Sensors/Accelerometer/LIS331HH.pdf)&lt;/A&gt; sensor.&amp;nbsp; &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I communicate to it using the I2C protocol (&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fi2c.info%2Fi2c-bus-specification" rel="nofollow" target="_blank"&gt;http://i2c.info/i2c-bus-specification&lt;/A&gt;), and when I write to it I always have success, but when reading from it, after writing, from a different function, the code errors after the repeated start saying it got a nack flag.&amp;nbsp; However it never seems to send the SUB address, which has its own failure code, and never fails there.&amp;nbsp; But it fails much later in the code after the repeated start.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the Kinetis API &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.nxp.com%2Fassets%2Fdocuments%2Fdata%2Fen%2Freference-manuals%2FKSDK20APIRM.pdf" rel="nofollow" target="_blank"&gt;http://www.nxp.com/assets/documents/data/en/reference-manuals/KSDK20APIRM.pdf&lt;/A&gt;, however I have ripped the guts from some of the functions and put them directly in my code.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The write_register function succeeds, each and every time.&lt;/P&gt;&lt;P&gt;In the read_sensor function (where there is a problem):&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first 8 bits are the hex value 0x32 (b 00110010) which is the write address.&amp;nbsp; After the last 0 bit you get another zero bit (the ack).&amp;nbsp; You can see this on the Read Zoom.png logic analyzer image attached.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After this should be the register address from which to read, in this case (0x20), but it somehow fails attempting to read from this.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at the logic analyzer images, you can see the only thing that succeeded is sending the slave address, (0x32), and not the sub address.&amp;nbsp; Though running the code gives you the error that the repeated start failed (nack), even though it never got that.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is unclear to me as to why this fails?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do the entire write and then read sequence in one function, it succeeds.&amp;nbsp; Seperating the read register from write to register out into two functions makes the read operation fail.&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached are the logic analyzer outputs&amp;nbsp;&lt;/P&gt;&lt;P&gt;Write Read.png (write first block - read second block)&lt;/P&gt;&lt;P&gt;Read Zoom.png (read zoomed in - so failure can be seen)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the code.&lt;/P&gt;&lt;P&gt;sensor.c&amp;nbsp; - contains read_sensor and write_register&lt;/P&gt;&lt;P&gt;main() function - calls init board functions and calling both functions&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first function returns 0 (success)&lt;/P&gt;&lt;P&gt;The second function prints "Got nak flag on repeated start"&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-337642"&gt;sensor.c.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 May 2017 00:19:44 GMT</pubDate>
    <dc:creator>tonythelion</dc:creator>
    <dc:date>2017-05-22T00:19:44Z</dc:date>
    <item>
      <title>FRDM-K22F I2C Failure with sensor</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-I2C-Failure-with-sensor/m-p/687545#M42324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a kinetis FRDM-F22 board connected to an LIS331H (&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fwww.sparkfun.com%2Fdatasheets%2FSensors%2FAccelerometer%2FLIS331HH.pdf" rel="nofollow" target="_blank"&gt;https://www.sparkfun.com/datasheets/Sensors/Accelerometer/LIS331HH.pdf)&lt;/A&gt; sensor.&amp;nbsp; &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I communicate to it using the I2C protocol (&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fi2c.info%2Fi2c-bus-specification" rel="nofollow" target="_blank"&gt;http://i2c.info/i2c-bus-specification&lt;/A&gt;), and when I write to it I always have success, but when reading from it, after writing, from a different function, the code errors after the repeated start saying it got a nack flag.&amp;nbsp; However it never seems to send the SUB address, which has its own failure code, and never fails there.&amp;nbsp; But it fails much later in the code after the repeated start.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the Kinetis API &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.nxp.com%2Fassets%2Fdocuments%2Fdata%2Fen%2Freference-manuals%2FKSDK20APIRM.pdf" rel="nofollow" target="_blank"&gt;http://www.nxp.com/assets/documents/data/en/reference-manuals/KSDK20APIRM.pdf&lt;/A&gt;, however I have ripped the guts from some of the functions and put them directly in my code.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The write_register function succeeds, each and every time.&lt;/P&gt;&lt;P&gt;In the read_sensor function (where there is a problem):&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first 8 bits are the hex value 0x32 (b 00110010) which is the write address.&amp;nbsp; After the last 0 bit you get another zero bit (the ack).&amp;nbsp; You can see this on the Read Zoom.png logic analyzer image attached.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After this should be the register address from which to read, in this case (0x20), but it somehow fails attempting to read from this.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at the logic analyzer images, you can see the only thing that succeeded is sending the slave address, (0x32), and not the sub address.&amp;nbsp; Though running the code gives you the error that the repeated start failed (nack), even though it never got that.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is unclear to me as to why this fails?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do the entire write and then read sequence in one function, it succeeds.&amp;nbsp; Seperating the read register from write to register out into two functions makes the read operation fail.&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached are the logic analyzer outputs&amp;nbsp;&lt;/P&gt;&lt;P&gt;Write Read.png (write first block - read second block)&lt;/P&gt;&lt;P&gt;Read Zoom.png (read zoomed in - so failure can be seen)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the code.&lt;/P&gt;&lt;P&gt;sensor.c&amp;nbsp; - contains read_sensor and write_register&lt;/P&gt;&lt;P&gt;main() function - calls init board functions and calling both functions&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first function returns 0 (success)&lt;/P&gt;&lt;P&gt;The second function prints "Got nak flag on repeated start"&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-337642"&gt;sensor.c.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 May 2017 00:19:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-I2C-Failure-with-sensor/m-p/687545#M42324</guid>
      <dc:creator>tonythelion</dc:creator>
      <dc:date>2017-05-22T00:19:44Z</dc:date>
    </item>
  </channel>
</rss>

