cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H750 Type V - reading the Internal temperature sensor (ADC3)

WSHAN.1
Associate II

Hello,

I am trying to read the internal temperature sensor - but the value I get does not change at all (when I change the ambient temperature).

I have the same raw value from ADC - 0xe41 -- >, which convert to -142.19 C (?!)

I assume that something is wrong here.

the question is:

1 . Does this sensor work correctly on the H750 type V ? if so -

what am I doing wrong in the code ?

here the code :

main function --> read_internal_temperature_sensor

void MX_ADC3_Init(void)

{

 ADC_ChannelConfTypeDef sConfig = {0};

 /** Common config

 */

 hadc3.Instance = ADC3;

 hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV128;

 hadc3.Init.Resolution = ADC_RESOLUTION_12B;

 hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;

 hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc3.Init.LowPowerAutoWait = DISABLE;

 hadc3.Init.ContinuousConvMode = DISABLE;

 hadc3.Init.NbrOfConversion = 2;

 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 Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_0;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

 sConfig.OffsetSignedSaturation = DISABLE;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel

 */

 sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;

 sConfig.Rank = ADC_REGULAR_RANK_2;

 sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 |

}

MSD_status_t  read_internal_temperature_sensor (uint16_t* adc_converted)

{

MSD_status_t status = MSD_ST_OK;

uint16_t adc_value;

float adc_value_converted_f;

adc_set_channel(&hadc3, &adc3_sConfig_RunTime, ADC_CHANNEL_TEMPSENSOR);

adc_value = adc_read(&hadc3);

adc_value_converted_f = adjust_to_celcius(adc_value);

*adc_converted = (uint16_t)(adc_value_converted_f);

return status;

}

MSD_status_t adc_set_channel(ADC_HandleTypeDef* in_p_adc, ADC_ChannelConfTypeDef* in_p_adc_conf, uint32_t in_ul_channel)

{

MSD_status_t status = MSD_ST_OK;

in_p_adc_conf->Channel = in_ul_channel;

if (HAL_ADC_ConfigChannel(in_p_adc, in_p_adc_conf) != HAL_OK)

{

status = MSD_ST_NOT_READY;

}

return status;

}

#define ADC_WAIT_END_OF_GROUP_CONVER_MSEC ((uint32_t) (1500UL / portTICK_RATE_MS))

uint16_t adc_read(ADC_HandleTypeDef* in_p_adc)

{

uint32_t val;

HAL_ADC_Start(in_p_adc);

if (HAL_ADC_PollForConversion(in_p_adc, ADC_WAIT_END_OF_GROUP_CONVER_MSEC) == HAL_OK)

{

val = HAL_ADC_GetValue(in_p_adc);

}

else

{

return -1;

}

return (uint16_t)val;

}

// 0.0198f = (110-30)/4033 <-- TS_CAL2 = 0x4013 TS_CAL1 =0X3052 ,TS_CAL2_TEMP =110, //TS_CAL1_TEMP =30

//

// TS_CAL2_TEMP - TS_CAL1_TEMP  

//Temperature in °C ( ) = ------------------------------ × ( READ DATA - TS_CAL1) + TS_CAL1_TEMP

// TS_CAL2 - TS_CAL1  

float  adjust_to_celcius(uint16_t in_us_value)

{

float temp = (float)(0.0198f*(in_us_value - 0x3052)) + 30.0f;

return (temp*100);

}

2 REPLIES 2
Imen.D
ST Employee

Hello @WSHAN.1​ ,

Please add more details (question, issue) to your post in order to help you. 

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
WSHAN.1
Associate II

Done..