Merge branch 'bugfix/tsens_dis_ena' into 'master'

fix(temperature_sensor): Fix the value is incorrect if disable and enable again

Closes IDFGH-11766

See merge request espressif/esp-idf!28106
This commit is contained in:
C.S.M 2023-12-27 12:38:05 +08:00
commit 39882c30ae
2 changed files with 11 additions and 6 deletions

View File

@ -68,19 +68,20 @@ TEST_CASE("Double start error cause test", "[temperature_sensor]")
TEST_CASE("Double Start-Stop test", "[temperature_sensor]")
{
printf("Initializing Temperature sensor\n");
float tsens_out;
float tsens_result0;
float tsens_result1;
temperature_sensor_config_t temp_sensor = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
temperature_sensor_handle_t temp_handle = NULL;
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
TEST_ESP_OK(temperature_sensor_enable(temp_handle));
printf("Temperature sensor started\n");
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
printf("Temperature out celsius %f°C\n", tsens_out);
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_result0));
printf("Temperature out celsius %f°C\n", tsens_result0);
TEST_ESP_OK(temperature_sensor_disable(temp_handle));
TEST_ESP_OK(temperature_sensor_enable(temp_handle));
printf("Temperature sensor started again\n");
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
printf("Temperature out celsius %f°C\n", tsens_out);
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_result1));
printf("Temperature out celsius %f°C\n", tsens_result1);
TEST_ASSERT_FLOAT_WITHIN(4.0, tsens_result0, tsens_result1);
TEST_ESP_OK(temperature_sensor_disable(temp_handle));
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
}

View File

@ -51,6 +51,10 @@ void temperature_sensor_power_acquire(void)
temperature_sensor_ll_enable(true);
}
portEXIT_CRITICAL(&rtc_spinlock);
// After enabling/reseting the temperature sensor,
// the output value gradually approaches the true temperature
// value as the measurement time increases. 300us is recommended.
esp_rom_delay_us(300);
}
void temperature_sensor_power_release(void)