Temperature Sensor
Overview
The ESP32-S3 has a built-in temperature sensor used to measure the chip’s internal temperature, and hard to measure the environmental temperature accurately. Being built-in means that the temperature sensor should work on any ESP32-S3 regardless of what board the chip is embedded in. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC.
The conversion relationship is the first columns of the table below. Among them, offset = 0 is the main measurement option, and other values are extended measurement options.
offset |
measure range(Celsius) |
measure error(Celsius) |
---|---|---|
-2 |
50 ~ 125 |
< 3 |
-1 |
20 ~ 100 |
< 2 |
0 |
-10 ~ 80 |
< 1 |
1 |
-30 ~ 50 |
< 2 |
2 |
-40 ~ 20 |
< 3 |
Driver Usage
Initialize the temperature sensor by calling the function
temp_sensor_set_config()
and pass to it atemp_sensor_config_t
structure. Thetemp_sensor_config_t
structure should contain all the required parameters. See the example below.
temp_sensor_config_t temp_sensor = {
.dac_offset = TSENS_DAC_L2,
.clk_div = 6,
};
temp_sensor_set_config(temp_sensor);
Start the temp_sensor by calling :cpp:func:’temp_sensor_start’. The temperature sensor will now measure the temperature.
To get the current temperature, take the example below as a reference, the value you get is in Celsius.
float tsens_out;
temp_sensor_read_celsius(&tsens_out);
To stop the temperature sensor, please call :cpp:func:’temp_sensor_stop’.
Note
If you want dynamic reconfiguration, you need to stop the sensor first (temp_sensor_stop), set the new configuration (temp_sensor_set_config), then start the sensor again (temp_sensor_start).
Application Example
Temperature sensor reading example: peripherals/temp_sensor.
API Reference - Normal Temp Sensor
Functions
-
esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens)
Set parameter of temperature sensor.
- Parameters
tsens –
- Returns
ESP_OK Success
-
esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens)
Get parameter of temperature sensor.
- Parameters
tsens –
- Returns
ESP_OK Success
-
esp_err_t temp_sensor_start(void)
Start temperature sensor measure.
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG
-
esp_err_t temp_sensor_read_raw(uint32_t *tsens_out)
Read temperature sensor raw data.
- Parameters
tsens_out – Pointer to raw data, Range: 0 ~ 255
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG
tsens_out
is NULLESP_ERR_INVALID_STATE temperature sensor dont start
-
esp_err_t temp_sensor_read_celsius(float *celsius)
Read temperature sensor data that is converted to degrees Celsius.
Note
Should not be called from interrupt.
- Parameters
celsius – The measure output value.
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG ARG is NULL.
ESP_ERR_INVALID_STATE The ambient temperature is out of range.
Structures
-
struct temp_sensor_config_t
Configuration for temperature sensor reading.
Public Members
-
temp_sensor_dac_offset_t dac_offset
The temperature measurement range is configured with a built-in temperature offset DAC.
-
uint8_t clk_div
Default: 6
-
temp_sensor_dac_offset_t dac_offset
Enumerations
-
enum temp_sensor_dac_offset_t
temperature sensor range option.
Values:
-
enumerator TSENS_DAC_L0
offset = -2, measure range: 50℃ ~ 125℃, error < 3℃.
-
enumerator TSENS_DAC_L1
offset = -1, measure range: 20℃ ~ 100℃, error < 2℃.
-
enumerator TSENS_DAC_L2
offset = 0, measure range:-10℃ ~ 80℃, error < 1℃.
-
enumerator TSENS_DAC_L3
offset = 1, measure range:-30℃ ~ 50℃, error < 2℃.
-
enumerator TSENS_DAC_L4
offset = 2, measure range:-40℃ ~ 20℃, error < 3℃.
-
enumerator TSENS_DAC_MAX
-
enumerator TSENS_DAC_DEFAULT
-
enumerator TSENS_DAC_L0