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 default measurement option, and other values are extended measurement options.

Offset

Measurement Range (°C)

Measurement Error (°C)

-2

50 ~ 125

< 3

-1

20 ~ 100

< 2

0

-10 ~ 80

< 1

1

-30 ~ 50

< 2

2

-40 ~ 20

< 3

Driver Usage

  1. Initialize the temperature sensor by calling the function temp_sensor_set_config() and pass to it a temp_sensor_config_t structure. The temp_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);
  1. Start the temperature sensor by calling temp_sensor_start(), and then the sensor will start to measure the temperature.

  2. To get the current temperature, you can take the example below as a reference, and the temperatures you get are in Celsius.

float tsens_out;
temp_sensor_read_celsius(&tsens_out);
  1. To stop the temperature sensor, please call temp_sensor_stop().

备注

To realize dynamic reconfiguration, you need to stop the sensor first with temp_sensor_stop(), then set the new configuration with temp_sensor_set_config(), and then re-start the sensor with temp_sensor_start().

Application Example

For examples of the temperature sensor, please refer to 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.

参数

tsens

返回

  • ESP_OK Success

esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens)

Get parameter of temperature sensor.

参数

tsens

返回

  • ESP_OK Success

esp_err_t temp_sensor_start(void)

Start temperature sensor measure.

返回

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG

esp_err_t temp_sensor_stop(void)

Stop temperature sensor measure.

返回

  • ESP_OK Success

esp_err_t temp_sensor_read_raw(uint32_t *tsens_out)

Read temperature sensor raw data.

参数

tsens_out – Pointer to raw data, Range: 0 ~ 255

返回

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG tsens_out is NULL

  • ESP_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.

备注

Should not be called from interrupt.

参数

celsius – The measure output value.

返回

  • 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

struct tsens_dac_offset_t

tsens dac offset, internal use only

Public Members

int index

temperature dac offset index

int offset

temperature dac offset

int set_val

temperature dac set value

int range_min

temperature current range minimum

int range_max

temperature current range maximum

int error_max

temperature current range error

Macros

TSENS_ADC_FACTOR
TSENS_DAC_FACTOR
TSENS_SYS_OFFSET
TSENS_CONFIG_DEFAULT()

temperature sensor default setting.

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