NHS31xx SW API
tmeas: Temperature measurement module

Detailed Description

The temperature measurement module provides a simple yet flexible API allows the user to measure temperatures, choosing the measurement resolution and the output unit of measurement.

Diversity
This module supports diversity, like defining a callback at link time. Check Diversity Settings for all diversity parameters.
Note
This mod provides an implementation of the interrupt vector TSEN_IRQHandler and enables and disables the interrupt TSEN_IRQn. By including this mod you can thus no longer use the interrupt driver functionality.
This mod will initialize (enable a clock and provide power) the TSEN driver (by calling Chip_TSen_Init) prior to making a measurement, and de-initialize it when the measurement is complete. Using the TSEN HW block directly is thus highly discouraged when using this mod.
This mod will by default use the temperature calibration values as determined during production at the factory site. When a recalibration is in order, these values can be changed by changing the registers NSS_TSEN_T.SP1, NSS_TSEN_T.SP2 and NSS_TSEN_T.SP3 for the a, b resp. alpha parameters. See the temperature application note for details on this recalibration.
Example 1: measure temperature, waiting for the result
int32_t temperature = (int32_t)TMeas_Measure(TSEN_10BITS, TMEAS_FORMAT_CELSIUS, true, 0);
/* for 20.5 degrees Celsius, temperature will now equal 205 */
Example 2: measure temperature, receive the result in a callback
Callback:
/*#define TMEAS_CB App_TmeasCb*/ /* Uncomment and place this line of code in app_sel.h */
void App_TmeasCb(TSEN_RESOLUTION_T resolution, TMEAS_FORMAT_T format, uint32_t value, uint32_t context)
{
/* In this example:
* - resolution will equal TSEN_12BITS
* - format will equal TMEAS_FORMAT_NATIVE
* - for 20.5 degrees Celsius, value will now equal 0x44CD
* - context will equal 42
*/
}
Main code:
int errorcode = TMeas_Measure(TSEN_12BITS, TMEAS_FORMAT_NATIVE, false, 42);
/* errorcode will now equal 0. Program continues, and
* when the measurement is ready TmeasCb is called under interrupt.
*/

Modules

 Diversity Settings
 

Macros

#define TMEAS_ERROR   (-1)
 

Typedefs

typedef void(* pTMeas_Cb_t) (TSEN_RESOLUTION_T resolution, TMEAS_FORMAT_T format, int value, uint32_t context)
 

Enumerations

enum  TMEAS_FORMAT_T {
  TMEAS_FORMAT_NATIVE,
  TMEAS_FORMAT_KELVIN,
  TMEAS_FORMAT_CELSIUS,
  TMEAS_FORMAT_FAHRENHEIT
}
 

Functions

int TMeas_Measure (TSEN_RESOLUTION_T resolution, TMEAS_FORMAT_T format, bool synchronous, uint32_t context)
 

Macro Definition Documentation

◆ TMEAS_ERROR

#define TMEAS_ERROR   (-1)

Returned value of TMeas_Measure to indicate a measurement is already in progress.

Typedef Documentation

◆ pTMeas_Cb_t

typedef void(* pTMeas_Cb_t) (TSEN_RESOLUTION_T resolution, TMEAS_FORMAT_T format, int value, uint32_t context)

Callback function type to report temperature measurement results.

See also
TMeas_Measure
Parameters
resolution: The value as given when TMeas_Measure was called.
format: The value as given when TMeas_Measure was called.
value: The measured temperature, converted to the format given by format. For the NATIVE format, the 16 LSBits are to be used. For all other formats, temperature is to be cast to an int32_t.
context: The value as given when TMeas_Measure was called.

Enumeration Type Documentation

◆ TMEAS_FORMAT_T

Possible temperature output formats.

Enumerator
TMEAS_FORMAT_NATIVE 

Signed 10.6 fixed point in Kelvin.

TMEAS_FORMAT_KELVIN 

Deci-degrees in Kelvin.

See also
http://en.wikipedia.org/wiki/Kelvin
TMEAS_FORMAT_CELSIUS 

Deci-degrees in Celsius.

See also
http://en.wikipedia.org/wiki/Celsius
TMEAS_FORMAT_FAHRENHEIT 

Deci-degrees in Fahrenheit.

See also
http://en.wikipedia.org/wiki/Fahrenheit

Function Documentation

◆ TMeas_Measure()

int TMeas_Measure ( TSEN_RESOLUTION_T  resolution,
TMEAS_FORMAT_T  format,
bool  synchronous,
uint32_t  context 
)

Make one temperature measurement.

Parameters
resolution: The required resolution. The higher the resolution, the longer it takes to take one measurement.
format: The required output format.
synchronous: Not looked at when TMEAS_CB is not defined; true is then always assumed. Else:
  • If true the function is synchronous, and will only return once the measurement is complete.
  • Else the function is asynchronous; it will return immediately, and once the temperature sensor has completed its measurement, the temperature is reported via the callback function TMEAS_CB.
context: Context information for the caller. You can fill in any value here: it is not used by this mod, only stored and sent back in a later call to TMEAS_CB. Use this as an aid for your own housekeeping, or disregard this argument: it doesn't impede the mod's working in any way.
Returns
  • If no measurement could be taken (TSEN HW block in use), TMEAS_ERROR is returned.
  • Else, if synchronous equals true, the measured temperature.
  • Else, 0 to indicate a measurement is ongoing and the callback will be called when the measurement is ready.
Note
TMEAS_CB will be called under interrupt.
This function is not re-entrant.
See also
pTMeas_Cb_t