Question
Stm32L562 Internal Temperature sensor reading is not right?
float read_internal_temperature(void)
{
uint32_t adcValue;
float temperature;
// Configure ADC channel for temperature sensor
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
// Start conversion and wait for it to complete
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
// Read ADC value
adcValue = HAL_ADC_GetValue(&hadc1);
// Retrieve calibration values from system memory
uint16_t ts_cal1 = TS_CAL1; // Calibration value at 30°C
uint16_t ts_cal2 = TS_CAL2; // Calibration value at 110°C
// Calculate the slope between TS_CAL1 and TS_CAL2
float slope = (float)(ts_cal2 - ts_cal1) / (110.0f - 30.0f);
// Calculate the temperature
temperature = 30.0f + ((float)(adcValue - ts_cal1) / slope);
// Stop ADC to save power
HAL_ADC_Stop(&hadc1);
return temperature;
}
The adcValue returns very low value although I am using a 12 bit resolutio
