cancel
Showing results for 
Search instead for 
Did you mean: 

stm32h743zit6 internal temperature sensor

ram_1
Associate

I am using stm32h743zitx nucleo board and thermal camera ,but in nucleo board stm32h743zitx internal temperature came 32 to 35 degree but same code i am using thermal camera than stm32h743zitx internal temperature came 123 and going above degree why i upload my code below please give me sollution where is my problem .i am using both 400 Mhz clock ....

float temperature;
uint32_t temperature_1 = 0;
uint32_t adcValue = 0;
uint32_t vrefint = 0;
uint32_t temp_sensor = 0;
 
float vrefint_volts;
float temperature_celsius;
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */
  

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  MX_ADC3_Init();

  while (1)
    {
        temperature = Get_Temperature(&vrefint_volts, &temperature_celsius);
        // Use the temperature value as needed
        HAL_Delay(1000);
    }

}
uint32_t Get_Temperature(float *vrefint_volts, float *temperature_celsius)
{
    
     HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
	  HAL_Delay(100);
    // Start ADC conversion for temperature sensor
    HAL_ADC_Start(&hadc3);
    if (HAL_ADC_PollForConversion(&hadc3, 100) == HAL_OK)
    {
        temp_sensor = HAL_ADC_GetValue(&hadc3);
    }
    HAL_ADC_Stop(&hadc3);

    // Read the calibration values
    uint16_t cal1 = *TEMPSENSOR_CAL1_ADDR;
    uint16_t cal2 = *TEMPSENSOR_CAL2_ADDR;
    uint16_t vrefint_cal = *VREFINT_CAL_ADDR;

    // Calculate the analog reference voltage (Vref+) in millivolts
    vrefint = __HAL_ADC_CALC_VREFANALOG_VOLTAGE(vrefint_cal, ADC_RESOLUTION_16B);
    *vrefint_volts = vrefint / 1000.0f;  // Convert millivolts to volts

//    // Calculate temperature in degrees Celsius
   *temperature_celsius = (float)__HAL_ADC_CALC_TEMPERATURE(vrefint, temp_sensor, ADC_RESOLUTION_16B);
    return (uint32_t)*temperature_celsius;
}

ADC_HandleTypeDef hadc3;

/* ADC3 init function */
void MX_ADC3_Init(void)
{
    ADC_ChannelConfTypeDef sConfig = {0};

    /* Configure ADC3 peripheral */
    hadc3.Instance = ADC3;
    hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV6;
    hadc3.Init.Resolution = ADC_RESOLUTION_16B; // ADC resolution for internal temperature sensor
    hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
    hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    hadc3.Init.LowPowerAutoWait = DISABLE;
    hadc3.Init.ContinuousConvMode = DISABLE;
    hadc3.Init.NbrOfConversion = 1;
    hadc3.Init.DiscontinuousConvMode = DISABLE;
    hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
    hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
    hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
    hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
    hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
    hadc3.Init.OversamplingMode = DISABLE;
    if (HAL_ADC_Init(&hadc3) != HAL_OK)
    {
        Error_Handler();
    }

    /* Configure the ADC channel for temperature sensor */
    __HAL_RCC_VREF_CLK_ENABLE(); // Enable VREFINT clock
    sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
    sConfig.Rank = ADC_REGULAR_RANK_1;
    sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;
    sConfig.SingleDiff = ADC_SINGLE_ENDED;
    sConfig.OffsetNumber = ADC_OFFSET_NONE;
    sConfig.Offset = 0;
    if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
    {
        Error_Handler();
    }
}

#define VREFINT_CAL_ADDR                   ((uint16_t*) (0x1FF1E860UL)) /* Internal voltage reference, address of parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */
#define VREFINT_CAL_VREF                   (3300UL)                     /* Analog voltage reference (Vref+) value with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */
/* Temperature sensor */
#define TEMPSENSOR_CAL1_ADDR               ((uint16_t*) (0x1FF1E820UL)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32H7, temperature sensor ADC raw data acquired at temperature  30 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL2_ADDR               ((uint16_t*) (0x1FF1E840UL)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32H7, temperature sensor ADC raw data acquired at temperature 110 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */
#define TEMPSENSOR_CAL1_TEMP               (30L)                        /* 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               (110L)                       /* 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          (3300UL)                     
2 REPLIES 2
mƎALLEm
ST Employee

Almost the same thread: https://community.st.com/t5/stm32-mcus-embedded-software/stm32h743zit6-internal-temperature-sensor-reading/m-p/714636#M50914

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.
mƎALLEm
ST Employee

Hello,

You can refer to this article: How to measure the junction temperature of an STM32H7

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.