<?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: MPL3115A2 temperature conversion in Sensors</title>
    <link>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853525#M5394</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Tomas, thank you for answer. &lt;/P&gt;&lt;P&gt;Code-wise, your method is the same as my last one, which I found working. But yours is optimized better. Thank you for help, now everything is clear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Apr 2019 12:35:42 GMT</pubDate>
    <dc:creator>lukaszprzeniosl</dc:creator>
    <dc:date>2019-04-15T12:35:42Z</dc:date>
    <item>
      <title>MPL3115A2 temperature conversion</title>
      <link>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853523#M5392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;I am having a problem with understanding how to convert the the MPL3115A2 temperature readings exactly (OUT_T_MSB, OUT_T_LSB). Please consider this function:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;inline static float rawTemperature2Float(const uint8_t* const rt)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return ((float)((int8_t)rt[0])) + (((rt[1] &amp;gt;&amp;gt; 4) &amp;amp; 0x0F) * 0.0625f);&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;rt[0] = OUT_T_MSB and rt[1] = OUT_T_LSB.&lt;/P&gt;&lt;P&gt;The question is: Does the sign bit in MSB also determinate how should the fractional part be treated, or is it always positive? In the presented function I am always adding the fractional part. But maybe if the sign is negative, I should substract it (or multiply by -1)? Should the function look 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;inline static float rawTemperature2Float(const uint8_t* const rt)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;float frac = ((rt[1] &amp;gt;&amp;gt; 4) &amp;amp; 0x0F) * 0.0625f;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (rt[0] &amp;amp; 0x80)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;frac *= -1; // variant #1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //frac = (1.0f - frac) * -1; // variant #2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return ((float)((int8_t)rt[0])) + frac;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If so, which variant in the if?&lt;/P&gt;&lt;P&gt;This approach gives similar results (all bits threaded for twos complement conversion):&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;inline static float rawTemperature2Float(const uint8_t* const rt)&lt;BR /&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int32_t temp = (((int32_t)rt[0]) &amp;lt;&amp;lt; 4) | (rt[1] &amp;gt;&amp;gt; 4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (temp &amp;amp; 0x800)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = (0x1000 - temp) * -1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return ((float)(temp)) / 16.0f;&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I would appreciate all help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Feb 2026 22:05:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853523#M5392</guid>
      <dc:creator>lukaszprzeniosl</dc:creator>
      <dc:date>2026-02-03T22:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: MPL3115A2 temperature conversion</title>
      <link>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853524#M5393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Lukasz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do apologize for my delayed response, but I was on a business trip last week with a limited time to react on community questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my code I use the following formula:&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;SPAN style="color: black; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;Temperature = (&lt;/SPAN&gt;&lt;SPAN style="color: #7f0055; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;&lt;STRONG style="border: 0px; font-weight: bold; font-size: 13.3333px;"&gt;float&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: black; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;) ((&lt;/SPAN&gt;&lt;SPAN style="color: #7f0055; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;&lt;STRONG style="border: 0px; font-weight: bold; font-size: 13.3333px;"&gt;short&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: black; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;)((RawData[3] &amp;lt;&amp;lt; 8) | (RawData[4] &amp;amp; 0xF0)) &amp;gt;&amp;gt; 4) * 0.0625;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;SPAN style="color: black; border: 0px; font-weight: inherit; font-size: 10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You need to get -0.0625 for RawData[3] = OUT_T_MSB = FF and RawData[4] = OUT_T_LSB = F0.&lt;/P&gt;&lt;P&gt;I will retest it again tomorrow when I am back in the office, but if I remember well, I really got -0.0625 for 0xFFF0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="border: 1pt none windowtext; font-weight: inherit; font-size: 9pt; padding: 0in;"&gt;PS:&amp;nbsp;If&amp;nbsp;this answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:24:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853524#M5393</guid>
      <dc:creator>TomasVaverka</dc:creator>
      <dc:date>2019-04-15T12:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: MPL3115A2 temperature conversion</title>
      <link>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853525#M5394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Tomas, thank you for answer. &lt;/P&gt;&lt;P&gt;Code-wise, your method is the same as my last one, which I found working. But yours is optimized better. Thank you for help, now everything is clear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Apr 2019 12:35:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Sensors/MPL3115A2-temperature-conversion/m-p/853525#M5394</guid>
      <dc:creator>lukaszprzeniosl</dc:creator>
      <dc:date>2019-04-15T12:35:42Z</dc:date>
    </item>
  </channel>
</rss>

