cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474RE Internal temperature sensor returning very low value

RPG
Senior

Hi

I am trying to make work the internal temperature sensor from a STM32G474RE and it seems to return a low value... 11.14 celsius degrees.

This is the code I am using:

#define TS_CAL1_ADDR ((uint16_t*) ((uint32_t)0x1FFF75A8))
#define TS_CAL2_ADDR ((uint16_t*) ((uint32_t)0x1FFF75CA))
#define TS_CAL1_TEMP 30.0
#define TS_CAL2_TEMP 130.0
 
double getTemperatureMCUPCB(void) {
	uint32_t TS_CAL1 = (int32_t) * TS_CAL1_ADDR;
	uint32_t TS_CAL2 = (int32_t) * TS_CAL2_ADDR;
	mcuPCBTempADCValue = global_adc1_val[1];
	mcuPCBTemperature = ((TS_CAL2_TEMP - TS_CAL1_TEMP)/((double)TS_CAL2 - (double)TS_CAL1)) * ((double)mcuPCBTempADCValue*(3.3/3.0) - (double)TS_CAL1) + 30.0;
 
	printf("MCU temp: %.2f\n", mcuPCBTemperature);
 
	return mcuPCBTemperature;
}

And this is how is setup ADC1:


_legacyfs_online_stmicro_images_0693W00000bjQERQA2.png
_legacyfs_online_stmicro_images_0693W00000bjQEWQA2.png

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Did you calibrate ADC before use?

Here are some other related hints.

JW

View solution in original post

3 REPLIES 3

Did you calibrate ADC before use?

Here are some other related hints.

JW

No, I did not. I will check out the datasheet and the reference manual tomorrow to see how to perform a calibration. I didn’t know about it. It seems to read well the voltages in other parts of the code. But I will look into it. Thanks.

Calibration did the trick. Thanks a lot 🙂