espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.38k stars 7.22k forks source link

esp32c3 internal temperature sensor report wrong values (IDFGH-7880) #9404

Open bbinet opened 2 years ago

bbinet commented 2 years ago

Environment

Problem Description

My code makes use of the built-in sensor to measure the chip’s internal temperature, but the reported temperature value seems to be wrong. Actually, I've done the following test: I've connected some one-wire temperature sensors to my esp32c3 device and I've put everything in an oven at around 60°C temperature to check if the esp32c3 internal temperature was correct. Here are the results: image sensor.CPU is the chip’s internal temperature, and sensor.T1/T2/T3 are 3 external 1-wire temperature sensors. As you can see in the graph, the chip’s internal temperature seem to be wrong.

Steps to reproduce

Simply use esp32c3 temperature sensor API from https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/peripherals/temp_sensor.html and check if temperature value is correct.

mythbuster5 commented 2 years ago

Thanks @bbinet . Could you post your temperature sensor related code, and we can check the usage

bbinet commented 2 years ago

@mythbuster5 sure, here is the related code:

esp_err_t hl_system_init(hl_spsn_priv_data_t *spsn)
{
    TR_CHECK_HANDLE(spsn, ESP_ERR_INVALID_STATE);

    ESP_LOGI(TAG, "Init temperature sensor, expected temp range: -10~80°C");
    temperature_sensor_config_t t_sensor_config = 
        TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(-10, 80);
    spsn->t_sensor = NULL;
    return temperature_sensor_install(&t_sensor_config, &spsn->t_sensor);
}

and:

esp_err_t hl_system_run(hl_spsn_priv_data_t *spsn) {
    float tsens = 0;
    int tsens_int = 0;
    esp_err_t ret = temperature_sensor_enable(spsn->t_sensor);
    if (ret == ESP_OK) {
        ret = temperature_sensor_get_celsius(spsn->t_sensor, &tsens);
        tsens_int = (int) ((tsens < 0) ? (tsens - 0.5) : (tsens + 0.5));
        temperature_sensor_disable(spsn->t_sensor);
        ESP_LOGI(TAG, "Internal temperature sensor=%d°C", tsens_int);
    } else {
        ESP_LOGW(TAG, "Failed to enable temperature sensor");
    }
    rtcmem.data[rtcmem.cur++] = (ret == ESP_OK) ? tsens_int : 0;

    return ret;
}
joesensoric commented 1 year ago

I can confirm this issue. I'm using a Seeed Studio XIAO ESP32C3 with the IDF version v5.1-dev and the example code from https://github.com/espressif/esp-idf/tree/master/examples/peripherals/temp_sensor

When I first run the example I got a temperature of 21°C, after that only values between 33 and 34°C. Also when the module was offline for hours or the environment temperature changes between 14 an 25°C, the internal temperature sensor reports 33.5°C most of the time. I never got a value below that again. Is there any kind of calibration made and saved?

AxelLin commented 1 year ago

Thanks @bbinet . Could you post your temperature sensor related code, and we can check the usage

@mythbuster5 Any update for this issue?