2.120 Temperature Measurement (TSENS)

Using the Library

TSENS Interrupt
#include <stddef.h>                     // Defines NULL
#include <stdbool.h>                    // Defines true
#include <stdlib.h>                     // Defines EXIT_FAILURE
#include <stdio.h>
#include "definitions.h"                // SYS function prototypes

#define TEMP_RESOLUTION (100U)
uint32_t result;
volatile bool result_ready;
float temp; 

void result_handler(TSENS_STATUS status, uintptr_t context )
{
    result = TSENS_ConversionResultGet();
    result_ready = true;
}

// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************

int main ( void )
{
    /* Initialize all modules */
    SYS_Initialize ( NULL );
    
    printf("\n\r---------------------------------------------------------");
    printf("\n\r                    TSENS Temperature Measurement                 ");
    printf("\n\r---------------------------------------------------------\n\r");
    
    TSENS_Enable();
    TC0_TimerStart();
    TSENS_CallbackRegister(result_handler, (uintptr_t) NULL);
    
    while (1)
    {
        /* Wait till conversion result is available */
        if (result_ready)
        {
             /* Read the result */
            result_ready = false;
            temp = (float)result / TEMP_RESOLUTION;

            printf(" TSENS Count = 0x%x    Temperature = %d.%02d celcius \r", (int)result, (int)temp, (int)((temp - (int)temp)*100.0));
        }
    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}


/*******************************************************************************
 End of File
*/

Library Interface

Temperature Measurement peripheral library provides the following interfaces:

Functions

NameDescription
TSENS_InitializeInitializes given TSENS peripheral
TSENS_EnableEnables given instance of TSENS peripheral
TSENS_DisableDisables given instance of TSENS peripheral
TSENS_InterruptsEnableEnables given interrupts
TSENS_InterruptsDisableDisables given interrupts
TSENS_InterruptsClearClears given interrupts
TSENS_ComparisonWindowSetConfigures low threshold and high threshold window values
TSENS_ConversionResultGetReturns the measured temperature value
TSENS_ConversionStartStarts the temperature measurement
TSENS_ConversionStatusGetReturns the status of the temperature measurement
TSENS_WindowModeSetConfigures the comparison window mode
TSENS_WindowMonitorStatusGetRead the status of the window monitor comparison
TSENS_CallbackRegisterRegisters the function to be called from interrupt

Data types and constants

NameTypeDescription
TSENS_WINMODEEnumIdentifies the window monitor mode
TSENS_CALLBACKTypedefDefines the data type and function signature for the TSENS peripheral callback function
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.