How to use the on-chip temperature sensor?

tobewinner
Posts: 30
Joined: Thu Dec 10, 2015 5:27 am

How to use the on-chip temperature sensor?

Postby tobewinner » Thu Sep 21, 2017 7:59 am

In esp32_technical_reference_manual, It described the temperature sensor, but just mentioned SENS_SAR_TSENS_CTRL_REG and SENS_SAR_SLAVE_ADDR3_REG, not the using process.
I searched the idf sdk, and did some test:
1, In test_tsens.c:

Code: Select all

    SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S);
    SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S);
    CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
    CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
    SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP_FORCE);
    SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
    ets_delay_us(100);
    SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
    ets_delay_us(5);
    int res = GET_PERI_REG_BITS2(SENS_SAR_SLAVE_ADDR3_REG, SENS_TSENS_OUT, SENS_TSENS_OUT_S);
    printf("res=%d\n", res);
2, I worte a init func :

Code: Select all

    SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S);
    SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S);
    CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
    CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
    SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP_FORCE);
    SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP)
and a read func:

Code: Select all

	Ret = 3;
	SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
	while (!((RegV=READ_PERI_REG(SENS_SAR_SLAVE_ADDR3_REG))&SENS_TSENS_RDY_OUT) && Ret) {
		ESP_LOGI(MOD_TAG, "SENS_SAR_SLAVE_ADDR3_REG=%Xh, r=%d.", RegV, Ret);
		vTaskDelay(10);
		Ret--;
	}
however, SENS_TSENS_RDY_OUT has never been set.
so what is the right progress to use the on-chip temperature sensor regs?


Who is online

Users browsing this forum: No registered users and 300 guests