2023-05-04 02:14 PM - edited 2023-11-20 06:26 AM
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:
Thanks in advance.
Solved! Go to Solution.
2023-05-04 02:35 PM
2023-05-04 02:35 PM
2023-05-04 02:51 PM
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.
2023-05-04 10:55 PM
Calibration did the trick. Thanks a lot :)