MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TSENS: Temperature Sensor Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Temperature Sensor (TSENS) module of MCUXpresso SDK devices.

Function groups

The TSENS driver supports initialization/configuration/operation for optimization/customization purpose.

Initialization and deinitialization

The function TSENS_Init() initializes the TSENS with specified configurations. The function TSENS_GetDefaultConfig() gets the default configurations.

The function TSENS_Deinit() disables all interrupts and the module clock.

Get temperature

The function TSENS_StartMeasurement starts a TSENS conversion.

The function TSENS_GetTemperature() gets the temperature value in last measurement.

Calibration configuration

The function TSENS_GetDefaultCalibrationConfig() gets the default calibration parameters.

The function TSENS_SetCalibrationConfig() configures calibration parameters.

Status

Provides functions to get the TSENS status.

Interrupt

Provides functions to enable/disable TSENS interrupts and set interrupt conditions.

Typical use case

TSENS basic Configuration

Example to get temperature through the usage of conversion ready interrupt. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/tsens

Data Structures

struct  tsens_config_t
 Configuration for Temperature sensor More...
 
struct  tsens_calibration_config_t
 Configuration for tsens clibration parameters More...
 

Macros

#define FSL_TSENS_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */`
 TSENS driver version. More...
 

Enumerations

enum  _tsens_interrupt_enable {
  kTSENS_ConversionReadyInterruptEnable,
  kTSENS_LowThresholdInterruptEnable = TSENS_IMSC_TLOE_MASK,
  kTSENS_HighThresholdInterruptEnable = TSENS_IMSC_THIE_MASK
}
 TSENS interrupt. More...
 
enum  _tsens_flags {
  kTSENS_LowCoarseRangeFlag = TSENS_SR_TRANLOC_MASK,
  kTSENS_HighCoarseRangeFlag = TSENS_SR_TRANHIC_MASK,
  kTSENS_LowFineRangeFlag = TSENS_SR_TRANLOF_MASK,
  kTSENS_HighFineRangeFlag = TSENS_SR_TRANHIF_MASK,
  kTSENS_ConversionSuccessFlag = TSENS_SR_TSUCC_MASK,
  kTSENS_ConversionReadyInterruptFlag = TSENS_RIS_RDYI_MASK << 16U,
  kTSENS_LowThresholdInterruptFlag,
  kTSENS_HighThresholdInterruptFlag
}
 TSENS status flags. More...
 
enum  tsens_resolution_mode_t {
  kTSENS_Resolution7bit = 2U,
  kTSENS_Resolution8bit,
  kTSENS_Resolution9bit,
  kTSENS_Resolution10bit,
  kTSENS_Resolution11bit,
  kTSENS_Resolution12bit
}
 TSENS resolution modes. More...
 
enum  tsens_output_mode_t {
  kTSENS_OutputRawData = 0U,
  kTSENS_OutputCalibratedData
}
 TSENS output modes. More...
 

Initialization and deinitialization

void TSENS_Init (TSENS_Type *base, const tsens_config_t *config)
 Enable the access to TSENS registers and initialize TSENS module. More...
 
void TSENS_Deinit (TSENS_Type *base)
 De-initialize TSENS module. More...
 
void TSENS_GetDefaultConfig (tsens_config_t *config)
 Gets the default configuration for TSENS. More...
 

Get temperature

static void TSENS_StartMeasurement (TSENS_Type *base)
 Start the coversion. More...
 
static uint32_t TSENS_GetTemperature (TSENS_Type *base)
 Get the temperature data in last measurement. More...
 

Calibration configuration

void TSENS_GetDefaultCalibrationConfig (TSENS_Type *base, tsens_calibration_config_t *caliConfig)
 Get the default calibration config. More...
 
void TSENS_SetCalibrationConfig (TSENS_Type *base, const tsens_calibration_config_t *caliConfig)
 Config calibration parameters,. More...
 

Interrupt interface

static void TSENS_SetLowTemperatureThreshold (TSENS_Type *base, uint16_t temperature)
 Set the low temperature threshold. More...
 
static void TSENS_SetHighTemperatureThreshold (TSENS_Type *base, uint16_t temperature)
 Set the high temperature threshold. More...
 
static void TSENS_EnableInterrupt (TSENS_Type *base, uint32_t mask)
 Enable the TSENS interrupts. More...
 
static void TSENS_DisableInterrupt (TSENS_Type *base, uint32_t mask)
 Disable the TSENS interrupts. More...
 

Status interface

static uint32_t TSENS_GetStatusFlags (TSENS_Type *base)
 Get TSENS status flags. More...
 
static uint32_t TSENS_GetInterruptStatusFlags (TSENS_Type *base)
 Get TSENS interrupt status flags. More...
 
static void TSENS_ClearInterruptStatusFlags (TSENS_Type *base, uint32_t mask)
 Clear interrupt status flags. More...
 

Data Structure Documentation

struct tsens_config_t

This structure holds the configuration settings for the temperature sensor. To initialize this structure to reasonable defaults, call the TSENS_GetDefaultConfig() function and pass a pointer to your config structure instance.

Data Fields

tsens_output_mode_t outputMode
 Set temperature sensor output mode. More...
 
tsens_resolution_mode_t resolutionMode
 Set temperature sensor resolution mode. More...
 
bool enableVolatgeCalibration
 Enable temperature sensor voltage calibration. More...
 

Field Documentation

tsens_output_mode_t tsens_config_t::outputMode
tsens_resolution_mode_t tsens_config_t::resolutionMode
bool tsens_config_t::enableVolatgeCalibration
struct tsens_calibration_config_t

This structure holds the configuration settings for the calibration parameters. To initialize this structure to reasonable defaults, call the TSENS_GetCalibrationDefaultConfig() function and pass a pointer to your config structure instance.

The calibration values A, B, and alpha for the default resolution settings are determined during the calibration phase of the manufacturing process and stored in EEPROM.

Data Fields

uint16_t parameterA
 Calibration parameter A.
 
uint16_t parameterB
 Calibration parameter B.
 
uint16_t parameterAlpha
 Calibration parameter ALPHA.
 

Macro Definition Documentation

#define FSL_TSENS_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */`

Enumeration Type Documentation

Enumerator
kTSENS_ConversionReadyInterruptEnable 

The temperature sensor conversion ready interrupt.

kTSENS_LowThresholdInterruptEnable 

The temperature sensor low threshold interrupt.

kTSENS_HighThresholdInterruptEnable 

The temperature sensor high threshold interrupt.

Enumerator
kTSENS_LowCoarseRangeFlag 

Coarse range mask, out of range (too low).

kTSENS_HighCoarseRangeFlag 

Coarse range mask, out of range (too high).

kTSENS_LowFineRangeFlag 

Fine range mask, out of range (too low).

kTSENS_HighFineRangeFlag 

Fine range mask, out of range (too low).

kTSENS_ConversionSuccessFlag 

Successful conversion mask.

kTSENS_ConversionReadyInterruptFlag 

A temperature conversion has finished.

kTSENS_LowThresholdInterruptFlag 

A temperature conversion has finished and the value is below the value stored in TLO.

kTSENS_HighThresholdInterruptFlag 

A temperature conversion has finished and the value exceeds the THI threshold value.

Enumerator
kTSENS_Resolution7bit 

7-bit resoultion mode

kTSENS_Resolution8bit 

8-bit resoultion mode

kTSENS_Resolution9bit 

9-bit resoultion mode

kTSENS_Resolution10bit 

10-bit resoultion mode

kTSENS_Resolution11bit 

11-bit resoultion mode

kTSENS_Resolution12bit 

12-bit resoultion mode

Enumerator
kTSENS_OutputRawData 

Raw data mode, unsigned fixed point (5.11)

kTSENS_OutputCalibratedData 

Calibrated data mode, signed fixed point (10.6)

Function Documentation

void TSENS_Init ( TSENS_Type *  base,
const tsens_config_t config 
)
Parameters
baseTSENS peripheral base address.
configPointer to configuration structure. Refer to "tsens_config_t" structure.
void TSENS_Deinit ( TSENS_Type *  base)
Parameters
baseTSENS peripheral base address.
void TSENS_GetDefaultConfig ( tsens_config_t config)

This function initializes the user configuration structure to default value. The default value are:

Parameters
configPointer to TSENS configuration structure. Refer to "tsens_config_t" structure.
static void TSENS_StartMeasurement ( TSENS_Type *  base)
inlinestatic
Parameters
basTSENS peripheral base address.
static uint32_t TSENS_GetTemperature ( TSENS_Type *  base)
inlinestatic
Parameters
baseTSENS peripheral base address.
Return values
Thetemperature value.
void TSENS_GetDefaultCalibrationConfig ( TSENS_Type *  base,
tsens_calibration_config_t caliConfig 
)
Parameters
baseTSENS peripheral base address.
caliConfigPointer to TSENS calibration configuration structure. Refer to "tsens_calibration_config_t" structure.
void TSENS_SetCalibrationConfig ( TSENS_Type *  base,
const tsens_calibration_config_t caliConfig 
)
Parameters
baseTSENS peripheral base address.
caliConfigPointer to TSENS calibration configuration structure. Refer to "tsens_calibration_config_t" structure.
static void TSENS_SetLowTemperatureThreshold ( TSENS_Type *  base,
uint16_t  temperature 
)
inlinestatic
Parameters
baseTSENS peripheral base address.
temperatureLow temperature threshold.
static void TSENS_SetHighTemperatureThreshold ( TSENS_Type *  base,
uint16_t  temperature 
)
inlinestatic
Parameters
baseTSENS peripheral base address.
temperaturehigh temperature threshold.
static void TSENS_EnableInterrupt ( TSENS_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basTSENS peripheral base address.
maskThe interrupt mask. Refer to "_tsens_interrupt" enumeration.
static void TSENS_DisableInterrupt ( TSENS_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basTSENS peripheral base address.
maskThe interrupt mask. Refer to "_tsens_interrupt" enumeration.
static uint32_t TSENS_GetStatusFlags ( TSENS_Type *  base)
inlinestatic

This function gets all TSENS status flags. The flags are returned as the logical OR value of the enumerators _tsens_flags. To check for a specific status, compare the return value with enumerators in the _tsens_flags. For example, to check whether the measurement value is ready in data register:

Parameters
baseTSENS peripheral base address.
Returns
TSENS status flags which are given in the enumerators in the _tsens_flags.
static uint32_t TSENS_GetInterruptStatusFlags ( TSENS_Type *  base)
inlinestatic

This function gets all TSENS interrupt status flags. The flags are returned as the logical OR value of the enumerators _tsens_interrupt_enable. To check for a specific status, compare the return value with enumerators in the _tsens_interrupt_enable. For example, to check whether the conversion ready interrupt is enabled:

Parameters
baseTSENS peripheral base address.
Returns
TSENS interrupt status flags which are given in the enumerators in the _tsens_interrupt_enable.
static void TSENS_ClearInterruptStatusFlags ( TSENS_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPADC peripheral base address.
maskMask value for interrupt flags to be cleared. Refer to "tsens_status_flags".