cancel
Showing results for 
Search instead for 
Did you mean: 

Getting temperature from STM32G491x internal temperature sensor ADC

JBend.6
Associate III

How to get temperature (degC) from the STM32G491x internal temperature sensor?

I have my ADC working and producing raw count values. Eg: 303.

So assuming a working voltage of 3V3 and maximum count value of 4095 then I assume that I must multiply the raw count value by (3.3 / 4095).

But then what? I cannot find any reference to a gain value.

Also, I understand that calibration is required. I used pointers to dereference the TC_CAL1 and TC_CAL2 addresses given in the DS13122 Rev 3 datasheet. (0x1FFF 75A8 - 0x1FFF 75A9).

	uint8_t * TC_CAL1;
	uint8_t * TC_CAL2;
 
	TC_CAL1 = 0x1FFF75A9;
	TC_CAL2 = 0x1FFF75A8;
 
	Calibration1 = *TC_CAL1;
	Calibration2 = *TC_CAL2;

Although the documentation does not say, I assume that these are the high and low values of a 16-bit value?

Then question is how to apply the calibration value? Should I add or subtract it from the final value derived from the raw value?

Please help.

16 REPLIES 16

@Community member​ Good point, in fact I hadn't noticed that before and it should definitely be corrected.

Thanks

/Peter

@Imen DAHMEN​ 

In order 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.
JBend.6
Associate III

Sorry for the confusion.

Yes, I am trying to use Temperature Sensor Channel with ADC5.

However, the issue is how to enable the VSENSESEL bit? Trawling through documentation the only reference I could find was LL call as follows:

LL_ADC_SetCommonPathInternalChAdd(ADCxy_COMMON *, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
HAL_ADC_Start_IT(&hadc5);

Assuming this is the correct approach to enabling the VSENSESEL bit and thus waking the Temperature Sensor...

What value am I supposed to provide for "ADCxy_COMMON *".

I find many references to this "ADC_Common_TypeDef" but no explanation.

Help!.

Hello All,

Thank you for rising this up.

Internal ticket (ID 154420) is submitted for correction.

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
JBend.6
Associate III

So after days trying to get this to work, it seems that ADC5 cannot be used for on-board Temperature Sensor on the STM32G474RETx.

It is working fine on ADC1.

> on the STM32G474RETx.

So, STM32G491x or STM32G474RETx.?

> it seems that ADC5 cannot be used for on-board Temperature Sensor

On which channel did you try to read?

Read out and check/post content of ADC registers.

JW

Datasheet temperature slope values don't match calibration values stored in part.  My STM32L072CZT6 is reading the calibration values stored in TS_CAL1&2 as 675mV (@30°C) and 911mV (@130°C).  Using these values gives me a slope of 2.36mV/°C.  The datasheet shows a nominal slope of 1.61mV/°C.  

I have a problem with my readings, too.  When I set my VDD to 3.0V (calibration conditions) and adjust my MCU temperature to 30°C, I get 604mV from the temperature sensor reading.  The stored calibration value for this condition reads as 675mV.  Can you help me resolve these differences?

Thanks,
Carl

OK, after I resolved my mistake of using the A/D counts and calling them mV, I still have my problem.  My measured value at 30° was 604, which did not match the stored calibration for 30°C (675).  We discovered that we were using only 12 clock cycles for our sampling time (way too quick).  Bumping the sampling time up to 160.5 clock cycles solved the problem, giving us data that matched our expectations.

I hope this display of my ignorance of the details helps somebody else avoid a few days of wasted time.

Thanks,
Carl