In this use case, the TSENS will measure the temperature using interrupt driven conversion.
When the temperature value has been measured, a callback will be called that signals the main application that the conversion is complete.
The TSENS will be set up as follows:
- GCLK generator 0 (GCLK main) clock source
- Free running disabled
- Run in standby
- Window monitor disabled
- All events (input and generation) disabled
- Calibration value which read from NVM or user set
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Add to the main application source file, outside of any functions:
Callback function:
{
tsens_read_done = true;
}
Copy-paste the following setup code to your user application:
Add to user application initialization (typically the start of main()
):
Workflow
- Create a module software instance structure for the TSENS module to store the TSENS driver state while it is in use.
- Note
- This should never go out of scope as long as the module is in use. In most cases, this should be global.
- Create a variable for the TSENS sample to be stored in by the driver asynchronously.
- Create a callback function that will be called each time the TSENS completes an asynchronous read job.
volatile bool tsens_read_done = false;
{
tsens_read_done = true;
}
- Configure the TSENS module.
- Create a TSENS module configuration struct, which can be filled out to adjust the configuration of a physical TSENS peripheral.
- Initialize the TSENS configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Set TSENS configurations.
- Enable the TSENS module so that conversions can be made.
- Register and enable the TSENS read complete callback handler.
- Register the user-provided read complete callback function with the driver, so that it will be run when an asynchronous read job completes.
- Enable the read complete callback so that it will generate callbacks.
Use Case
Code
Copy-paste the following code to your user application:
while (tsens_read_done == false) {
}
while (1) {
}
Workflow
- Enable interrupts, so that callbacks can be generated by the driver.
- Start an asynchronous TSENS conversion, to store TSENS sample into the variable and generate a callback when complete.
- Wait until the asynchronous conversion is complete.
while (tsens_read_done == false) {
}
- Enter an infinite loop once the conversion is complete.