In this use case we will interface the temperature sensor, set a resolution and read the temperature.
Prerequisites
The temperature sensor must be connected to the device.
Setup
Initialization Code
Add a global variable to store the temperature:
Copy-paste the following setup code to your application main function:
Workflow
- Initialize system
- Initialize I2C interface
Implementation
Code
Add after initialization in main.
volatile uint16_t thigh = 0;
volatile uint16_t tlow = 0;
while (1) {
}
Workflow
- Read THIGH register from temperature sensor:
volatile uint16_t thigh = 0;
- Read TLOW register from temperature sensor:
volatile uint16_t tlow = 0;
- Set temperature sensor resolution to 12-bit:
- Continuously read the temperature: