2.127 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
| Name | Description |
|---|---|
| TSENS_Initialize | Initializes given TSENS peripheral |
| TSENS_Enable | Enables given instance of TSENS peripheral |
| TSENS_Disable | Disables given instance of TSENS peripheral |
| TSENS_InterruptsEnable | Enables given interrupts |
| TSENS_InterruptsDisable | Disables given interrupts |
| TSENS_InterruptsClear | Clears given interrupts |
| TSENS_ComparisonWindowSet | Configures low threshold and high threshold window values |
| TSENS_ConversionResultGet | Returns the measured temperature value |
| TSENS_ConversionStart | Starts the temperature measurement |
| TSENS_ConversionStatusGet | Returns the status of the temperature measurement |
| TSENS_WindowModeSet | Configures the comparison window mode |
| TSENS_WindowMonitorStatusGet | Read the status of the window monitor comparison |
| TSENS_CallbackRegister | Registers the function to be called from interrupt |
Data types and constants
| Name | Type | Description |
|---|---|---|
| TSENS_WINMODE | Enum | Identifies the window monitor mode |
| TSENS_CALLBACK | Typedef | Defines 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.
