Skip to main content
Visitor II
September 2, 2024
Solved

stm32h743zit6 internal temperature sensor

  • September 2, 2024
  • 2 replies
  • 926 views

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) 
    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

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

    2 replies

    Technical Moderator
    September 2, 2024
    mƎALLEmAnswer
    Technical Moderator
    February 21, 2025

    Hello,

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