How to convert temperature sensor to C?
I'm trying to read the built-in temperature sensor on the MCU we're using (STM32L011F4P6)
We only have the one calibration datapoint, so I can't use the temperature conversion function I'm familiar with.
The code is as follows:
int32_t analog_get_temperature(void)
{
uint32_t temperature_reading;
int32_t temp_calc;
uint32_t u16vcc = analog_sample_vcc();
temperature_reading = analog_sample_channel(ADC_CHANNEL_TEMPSENSOR);
temp_calc = __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(TEMPERATURE_MV_PER_DEGREEC * 1000, *TEMPSENSOR_CAL2_ADDR, TEMPSENSOR_CAL2_TEMP, u16vcc, temperature_reading, LL_ADC_RESOLUTION_12B);
return temp_calc;
}
u16vcc is 3299, which is the same as what I measure with a voltmeter.
The calibration value at 0x1FF8007E is: 0x03A7
TEMPSENSOR_CAL2_TEMP is 130
The slope from the datasheet is:
#define TEMPERATURE_MV_PER_DEGREEC 1.61
The measured temperature_reading is: 614.
When we init the ADC: hadc.Init.Resolution = ADC_RESOLUTION_12B;
But the calculation tells me that it's -143C. I don't care how cold it feels outside in Wisconsin.... one, I'm not outside. Two, even then, it's not THAT cold!
Anyone spot what I'm missing?
