cancel
Showing results for 
Search instead for 
Did you mean: 

Where is the calibration data for the Temperature sensor in the STM32G031?

KiptonM
Lead

RM0444 Rev 5 Page 377 says

• TS_CAL2 is the temperature sensor calibration value acquired at TS_CAL2_TEMP

(refer to the datasheet for TS_CAL2 value)

• TS_CAL1 is the temperature sensor calibration value acquired at TS_CAL1_TEMP

(refer to the datasheet for TS_CAL1 value)

• TS_DATA is the actual temperature sensor output value converted by ADC

Refer to the specific device datasheet for more information about TS_CAL1 and

TS_CAL2 calibration points.

So I need to find TS_CAL1, TS_CAL2, TS_CAL2_TEMP, and TS_CAL1_TEMP

I go to DS12992 Rev 2 Page 24 Paragraph 3.14.1:

The temperature sensor (TS) generates a voltage V TS that varies linearly with temperature.

The temperature sensor is internally connected to an ADC input to convert the sensor

output voltage into a digital value.

The sensor provides good linearity but it has to be calibrated to obtain good overall

accuracy of the temperature measurement. As the offset of the temperature sensor may

vary from part to part due to process variation, the uncalibrated internal temperature sensor

is suitable only for relative temperature measurements.

To improve the accuracy of the temperature sensor, each part is individually factory-

calibrated by ST. The resulting calibration data are stored in the part’s engineering bytes,

accessible in read-only mode.

Table 5. Temperature sensor calibration values

Calibration value name Description Memory address

TS_CAL1

TS ADC raw data acquired at a

temperature of 30 °C (± 5 °C),

V DDA = V REF+ = 3.0 V (± 10 mV)

0x1FFF 75A8 - 0x1FFF 75A9

TS_CAL2

TS ADC raw data acquired at a

temperature of 130 °C (± 5 °C),

V DDA = V REF+ = 3.0 V (± 10 mV)

0x1FFF 75CA - 0x1FFF 75CB

So two of the 4 values I need are given in the documentation.

So I go to the CODE.

I Search for TS_CAL1, TS_CAL2, TS_CAL2_TEMP, TSCAL1_TEMP Not to be found except in a comment for a Macro that calculates a temperature based on their data. Found in stm32g0xx_ll_adc.h

/**
  * @brief  Helper macro to calculate the temperature (unit: degree Celsius)
  *         from ADC conversion data of internal temperature sensor.
  * @note   Computation is using temperature sensor calibration values
  *         stored in system memory for each device during production.
  * @note   Calculation formula:
  *           Temperature = ((TS_ADC_DATA - TS_CAL1)
  *                           * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  *                         / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  *           with TS_ADC_DATA = temperature sensor raw data measured by ADC
  *                Avg_Slope = (TS_CAL2 - TS_CAL1)
  *                            / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  *                TS_CAL1   = equivalent TS_ADC_DATA at temperature
  *                            TEMP_DEGC_CAL1 (calibrated in factory)
  *                TS_CAL2   = equivalent TS_ADC_DATA at temperature
  *                            TEMP_DEGC_CAL2 (calibrated in factory)
  *         Caution: Calculation relevancy under reserve that calibration
  *                  parameters are correct (address and data).
  *                  To calculate temperature using temperature sensor
  *                  datasheet typical values (generic values less, therefore
  *                  less accurate than calibrated values),
  *                  use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  * @note   As calculation input, the analog reference voltage (Vref+) must be
  *         defined as it impacts the ADC LSB equivalent voltage.
  * @note   Analog reference voltage (Vref+) must be either known from
  *         user board environment or can be calculated using ADC measurement
  *         and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  * @note   On this STM32 series, calibration data of temperature sensor
  *         corresponds to a resolution of 12 bits,
  *         this is the recommended ADC resolution to convert voltage of
  *         temperature sensor.
  *         Otherwise, this macro performs the processing to scale
  *         ADC conversion data to 12 bits.
  * @param  __VREFANALOG_VOLTAGE__  Analog reference voltage (unit: mV)
  * @param  __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  *                                 temperature sensor (unit: digital value).
  * @param  __ADC_RESOLUTION__      ADC resolution at which internal temperature
  *                                 sensor voltage has been measured.
  *         This parameter can be one of the following values:
  *         @arg @ref LL_ADC_RESOLUTION_12B
  *         @arg @ref LL_ADC_RESOLUTION_10B
  *         @arg @ref LL_ADC_RESOLUTION_8B
  *         @arg @ref LL_ADC_RESOLUTION_6B
  * @retval Temperature (unit: degree Celsius)
  *         In case or error, value LL_ADC_TEMPERATURE_CALC_ERROR is returned (inconsistent temperature value)
  */
#define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
                                  __TEMPSENSOR_ADC_DATA__,\
                                  __ADC_RESOLUTION__)\
((((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) != 0) ?        \
  (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__),     \
                                                    (__ADC_RESOLUTION__),          \
                                                    LL_ADC_RESOLUTION_12B)         \
                   * (__VREFANALOG_VOLTAGE__))                                     \
                  / TEMPSENSOR_CAL_VREFANALOG)                                     \
        - (int32_t) *TEMPSENSOR_CAL1_ADDR)                                         \
     ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP)                    \
    ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
   ) + TEMPSENSOR_CAL1_TEMP                                                        \
  )                                                                                \
  :                                                                                \
  ((int32_t)LL_ADC_TEMPERATURE_CALC_ERROR)                                         \
)

So here it looks like they use TS_CAL1_TEMP in the equation, but call it TEMP_DEGC_CAL1 in the description of TS_CAL1

And they do the same with TS_CAL2_TEMP calling it TEMP_DEGC_CAL2

Unfortunately I cannot find

TEMP_DEGC_CAL1

TEMP_DEGC_CAL2

defined ANYWHERE in the code either.

So how are we supposed to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

From the datasheet, it tells you the temperature at which those values are acquired:

0693W00000JPvkWQAT.png 

So TS_CAL1_TEMP = 30 and TS_CAL2_TEMP = 130, which is exactly how they're defined in the LL library.

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6c0046d9278a7107261c6bf38327345df4c3efd/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_ll_adc.h#L252

TEMP_DEGC_CAL1 and TS_CAL1_TEMP are equivalent and it should be corrected to use only one name.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
TDK
Guru

From the datasheet, it tells you the temperature at which those values are acquired:

0693W00000JPvkWQAT.png 

So TS_CAL1_TEMP = 30 and TS_CAL2_TEMP = 130, which is exactly how they're defined in the LL library.

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6c0046d9278a7107261c6bf38327345df4c3efd/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_ll_adc.h#L252

TEMP_DEGC_CAL1 and TS_CAL1_TEMP are equivalent and it should be corrected to use only one name.

If you feel a post has answered your question, please click "Accept as Solution".
KiptonM
Lead

No it is around 30C and around 130C They say +/- 5C. If they are off by 5 C then it is not calibrated. They need to tell the exact temperature they calibrated it at. not +/- 5C

KiptonM
Lead

Thanks for the pointer to the names that they used which is different again from the documentation and comments in the same file.

/* Temperature sensor */
#define TEMPSENSOR_CAL1_ADDR               ((uint16_t*) (0x1FFF75A8UL)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32G0, temperature sensor ADC raw data acquired at temperature  30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL2_ADDR               ((uint16_t*) (0x1FFF75CAUL)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32G0, temperature sensor ADC raw data acquired at temperature 130 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL1_TEMP               (( int32_t)   30)            /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */
#define TEMPSENSOR_CAL2_TEMP               (( int32_t)  130)            /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */
#define TEMPSENSOR_CAL_VREFANALOG          ( 3000UL)                    /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */

I'm not arguing with you regarding accuracy, but that's not how it's implemented. "Calibrated" is relative. If you need better precision than the datasheet specifies, you'll need to calibrate yourself.

If you feel a post has answered your question, please click "Accept as Solution".

I guess I am used to the TI MSP430. When they calibrate it is very accurate. I think +/-0.25 or 0.5 degrees C. Not an order of magnitude higher.

It still does not excuse the name difference. The same file uses different names in the comments.