ESP32-S2 Temperature Sensor

Overview

The ESP32-S2 has a built-in temperature sensor. 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

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.

Return
  • ESP_OK Success
Parameters
  • tsens:

esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens)

Get parameter of temperature sensor.

Return
  • ESP_OK Success
Parameters
  • tsens:

esp_err_t temp_sensor_start(void)

Start temperature sensor measure.

Return
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG

esp_err_t temp_sensor_stop(void)

Stop temperature sensor measure.

Return
  • ESP_OK Success

esp_err_t temp_sensor_read_raw(uint32_t *tsens_out)

Read temperature sensor raw data.

Return
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG tsens_out is NULL
  • ESP_ERR_INVALID_STATE temperature sensor dont start
Parameters
  • tsens_out: Pointer to raw data, Range: 0 ~ 255

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.
Return
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG ARG is NULL.
  • ESP_ERR_INVALID_STATE The ambient temperature is out of range.
Parameters
  • celsius: The measure output value.

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

Macros

TSENS_CONFIG_DEFAULT()

Enumerations

enum temp_sensor_dac_offset_t

Values:

TSENS_DAC_L0 = 0

offset = -2, measure range: 50℃ ~ 125℃, error < 3℃.

TSENS_DAC_L1

offset = -1, measure range: 20℃ ~ 100℃, error < 2℃.

TSENS_DAC_L2

offset = 0, measure range:-10℃ ~ 80℃, error < 1℃.

TSENS_DAC_L3

offset = 1, measure range:-30℃ ~ 50℃, error < 2℃.

TSENS_DAC_L4

offset = 2, measure range:-40℃ ~ 20℃, error < 3℃.

TSENS_DAC_MAX
TSENS_DAC_DEFAULT = TSENS_DAC_L2