PreviousNext
getTemperature
Help > OS functions > Other > getTemperature

Function

 

 Read temperature from the on-board sensor

Purpose

 

Temperature measurement

Syntax

 

int8 getTemperature()

Parameters

 

  –

Return value

 

     Temperature in °C, integer part, not rounded

     Negative temperatures are in two's complement format (e.g. 0xFB means -5 °C)

     0x80 (-128 °C) indicates an error in communication with the temperature sensor (temperature sensor damaged, not supplied, or not present, i.e. for TR modules without the “T” postfix, e.g. TR-72G.

Output values

 

param3: 12 b output value of the sensor in 0.0625 °C units. Thus, upper 8 b represent the integer part of the temperature, and lower 4 b represent the fractional part. The resolution is limited to 0.5 °C, therefore the lowest 3 b are always cleared. Negative temperatures are in the two's complement format. See the temperature sensor datasheet.

Examples:

 

Temperature

Return value

param3

 

Temperature

Return value

param3

50.0 °C

0x32

0x320

 

0.0 °C

0x00

0x000

5.0 °C

0x05

0x050

 

-0.5 °C

0xFF

0xFF8

5.5 °C

0x05

0x058

 

-1.0 °C

0xFF

0xFF0

0.5 °C

0x00

0x008

 

-8.5 °C

0xF7

0xF78

Preconditions

 

     Applicable for TRs equipped with temperature sensors only (e.g. for TR-72GT but not TR-72G).

     The power supply of the temperature sensor must not be disconnected. See macros eEEPROM_TempSensorOn and  eEEPROM_TempSensorOff.

     300 ms delay is required in LP or XLP RX mode, after reset, wake-up from sleep, or after eEEPROM_TempSensorOn.

Remarks

 

     Resolution 0.5 °C, accuracy: 0.5 °C

     Takes about 3 ms.

     See Example E08–TEMPERATURE.

Side effects

 

  –

See also

 

  –

Example 1

 

   // For positive temperatures only

int8   tempInt;                  // Temperature, integer part

uns8   tempFract;                // Temperature, fractional part

tempInt = getTemperature();

tempFract = param3.low8 & 0x0F;  // Temperature == tempInt + tempFract/16

                                  // Temperature == param3 * 0.0625 in °C

Example 2

 

   // Either positive or negative temperatures, fractional part ignored
T = getTemperature();            // Integer part of temperature

if (T > (uns8)0x80) {
   sign = ’-’;                   // Negative
   T = (T ^ 0xFF) + 1;           // Get absolute value in °C
}
else
   sign = ’+’;                   // Positive

Example 3

 

   // Either positive or negative temperatures, with fractional part

if (getTemperature() > (uns8)0x80) {

    sign = ’-’;                  // Negative

    T = (param3 ^ 0xFFF) + 1;    // Get absolute value, in 0.0625°C units

  }

else

   sign = ’+’;                   // Positive

Example 4

 

   // Temperature measurement after wake-up from sleep

iqrfSleep();

waitDelay(30);                   // 300 ms delay required

T = getTemperature();