<?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>Beginner&amp;#39;s questions on interpreting temperature data from nRF51822</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7442/beginner-s-questions-on-interpreting-temperature-data-from-nrf51822</link><description>I am using a function to read the die temperature data from nRF51822 as follows: 
 static uint32_t temperature_data_get(void)
{
 int32_t temp;
 uint32_t err_code;
 
 err_code = sd_temp_get(&amp;amp;temp);
 APP_ERROR_CHECK(err_code);
 
 temp = (temp </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Apr 2016 19:08:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7442/beginner-s-questions-on-interpreting-temperature-data-from-nrf51822" /><item><title>RE: Beginner's questions on interpreting temperature data from nRF51822</title><link>https://devzone.nordicsemi.com/thread/26527?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 19:08:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dee10643-6889-4c3e-8574-483f053f847d</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;That code is one of the Nordic examples in GitHub and I was wondering what was being achieved until I read this.  Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Beginner's questions on interpreting temperature data from nRF51822</title><link>https://devzone.nordicsemi.com/thread/26526?ContentTypeID=1</link><pubDate>Mon, 15 Jun 2015 19:27:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca371ec4-576f-409d-a6a5-50bfe34cd467</guid><dc:creator>diode</dc:creator><description>&lt;p&gt;Thanks so much! It is a very helpful answer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Beginner's questions on interpreting temperature data from nRF51822</title><link>https://devzone.nordicsemi.com/thread/26525?ContentTypeID=1</link><pubDate>Thu, 04 Jun 2015 23:58:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01ab616e-1bcb-4752-9399-a6a3864cd1a6</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Where did you get the idea that uint32_t has any relation to a single bit floating point number? It&amp;#39;s not, it&amp;#39;s a 32bit value packed with descriptive but fairly pointless data. Since you have the code right there you can see exactly what it is however. Where did that code come from?&lt;/p&gt;
&lt;p&gt;The bottom 24 bits are the read temperature value (which is in .25C increments) divided by 4 and multiplied by 100. So that&amp;#39;s just ( temperature X 100 ). Except it isn&amp;#39;t, because the division is in parantheses, done first and it&amp;#39;s integer division so that neatly throws away 2 bits of the precision you started with.&lt;/p&gt;
&lt;p&gt;eg if the temperature was 0.75, the sd_temp() function would return 3 (3 x .25 == .75) and the line&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;temp = ( temp / 4 ) * 100;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;would then convert that not to 75 (temperature X 100) but actually to 0. Doing the multiplication first and then the division would at least get that bit right, or even .. just multiplying by 25.&lt;/p&gt;
&lt;p&gt;It then packs a fixed -2 base 10 exponent in the MSB of the result, which I assume is supposed to tell the recipient to apply a 2 decimal point shift (decimal point, not binary point) shift to the result.&lt;/p&gt;
&lt;p&gt;If you start with the result you have. The upper fixed bits are 0xFE which are -2, you know they&amp;#39;re -2 because they were fixed to -2 but even if you didn&amp;#39;t 0xFE is 2&amp;#39;s complement of 2. The lower bits are 0xDAC which is 3,500 (your temperature X 100, apart from the loss of 2 bits) and indeed shifting the decimal point 2 places left (-2) gives you 35.&lt;/p&gt;
&lt;p&gt;Perhaps sending values in a pseudo base-10-floating-point-32-bit format is some kind of convention, if it is it&amp;#39;s not one I&amp;#39;ve seen. I wouldn&amp;#39;t bother myself unless whatever was on the other end wanted specifically that, I&amp;#39;d just send the reading and divide by 4, in floating point, on the recipient end which probably has floating point numbers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>