<?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>How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7134/how-can-i-convert-the-temperature-using-sd_temp_get-to-an-uint8_t</link><description>Hello 
 I am using the experimental_ble_app_uart for s110. I want to use the sd_temp_get() and convert the temperature value to a uint8_t, but if understand correctly when i do this i only get information from the first bytes of the int32_t and these</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Sep 2020 06:48:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7134/how-can-i-convert-the-temperature-using-sd_temp_get-to-an-uint8_t" /><item><title>RE: How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/thread/268184?ContentTypeID=1</link><pubDate>Mon, 07 Sep 2020 06:48:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f103625f-9e43-4d0e-af0f-720045af9660</guid><dc:creator>Embedded_Engineer</dc:creator><description>&lt;p&gt;Remember you are getting a 2&amp;#39;s complement in your int8_t &lt;code&gt;raw_temp so yes it is for negative values.&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you meant -5 degrees C then &lt;code&gt;it would be raw_temp = 0xFB;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you did not mean the above then we don&amp;#39;t write minus ( - ) with the hex. The most significant bit indicates &lt;code&gt;the sign. You can just compare the raw_temp with -5 and do your logic.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/thread/170363?ContentTypeID=1</link><pubDate>Mon, 11 Feb 2019 13:09:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5e09aea-d159-4ea4-a7dd-f2ab61cd8318</guid><dc:creator>puff</dc:creator><description>&lt;p&gt;Can&amp;#39;t understand, what will be the value for -5C? Will this code work for negative values?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/thread/25211?ContentTypeID=1</link><pubDate>Wed, 20 May 2015 10:26:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ac7d6ea-2602-462a-9a63-77751543c830</guid><dc:creator>Eirik Nobuki Kosaka</dc:creator><description>&lt;p&gt;Thanks! This helped and was able to make it work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/thread/25210?ContentTypeID=1</link><pubDate>Wed, 20 May 2015 05:01:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4e75f62-4a80-4ec0-8ca1-05dfd87040e8</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;In addition to Nick&amp;#39;s answer, you may need to calibrate the output of the TEMP peripheral.
The potential error read on the TEMP peripheral should be pure offset error. You can calibrate the temperature value in software, i.e. if you know the temperature in your room, just add or subtract from the measured value to get the correct value.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can i convert the temperature using sd_temp_get() to an uint8_t?</title><link>https://devzone.nordicsemi.com/thread/25209?ContentTypeID=1</link><pubDate>Tue, 19 May 2015 17:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:259d5204-fc16-4047-8b9e-78a383f04b09</guid><dc:creator>Nick Pelis</dc:creator><description>&lt;p&gt;The value from sd_temp_get() is in units of 0.25 degrees Celsius (&lt;a href="https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s110/html/a01073.html#gade0ea69f513ff1feab2c4f6e1c393313"&gt;source&lt;/a&gt;).  This means a value of 4 is 1 degree Celsius, a value of 8 is 2 degrees Celsius, a value of 12 is 3 degrees Celsius, etc.&lt;/p&gt;
&lt;p&gt;Assuming you wish to convert the result into a whole number, you would simply divide it by four.  I wouldn&amp;#39;t worry about any integer overflow as a result of going from a 32 bit to an 8 bit number since the operating range of the nrf514122 is between -25 and 75 degrees C.  However, since the temperature can drop below zero, you should use an int8_t instead of a uint8_t.&lt;/p&gt;
&lt;p&gt;So your code would look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int32_t raw_temp;
sd_temp_get(&amp;amp;raw_temp);
int8_t temp = raw_temp &amp;gt;&amp;gt; 2;  // divide by 4
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>