2026-03-09 1:25 PM
I'm trying to read a NTC temperature sensor, but the readings I'm getting are very inconsistent and at times just way off. I have nucleo on the way but this testing I'm doing is on a blue pill.
The sensor is sitting in a cup of water, so temperature should be very consistent. Here is the readings I'm getting which are done at 1 second intervals, I don't need speed. The temperature of the water is about 21C. The sensor accuracy is rated +/- 1.4C at 25C
Temp k: 293. c: 20.8
Temp k: 293. c: 20.7
Temp k: 294. c: 21.2
Temp k: 292. c: 19.5
Temp k: 307. c: 34.1
Temp k: 295. c: 22.3
Temp k: 294. c: 20.8
Temp k: 293. c: 20.7
Temp k: 294. c: 21.5
Temp k: 293. c: 20.7
Temp k: 294. c: 21.3
Temp k: 294. c: 21.4
Temp k: 293. c: 20.8
Temp k: 293. c: 20.5
Temp k: 294. c: 21.1
Temp k: 292. c: 19.7
Temp k: 266. c: -6.5
Temp k: 293. c: 20.5
Temp k: 293. c: 20.8
Temp k: 291. c: 18.8
Temp k: 266. c: -7.1
Temp k: 293. c: 20.6
Temp k: 294. c: 21.3
Temp k: 294. c: 21.3
Temp k: 293. c: 20.6
Temp k: 294. c: 20.9
Attached is the clock config. I've triad various settings, faster and slower.
ADC config:
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
How I'm reading at 1 second intervals:
if (HAL_OK == HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY)) {
vout = (HAL_ADC_GetValue(&hadc1) / 4095.0) * vin;
rout = rval * ((vin / vout) - 1);
temp_k = 1 / ((log(rout / rval) / coeff) + (1 / temp_base));
temp_c = temp_k - 273.15;
}
Solved! Go to Solution.
2026-03-09 1:51 PM
The product you are using is a so-called Blue Pill since years only containing clones of a genuine ST product.The seemingly small price advantage quickly evaporates, because you also need an ST-LINK. If one or both contain illegal clones, as the colourful tin cans do as well, you end up frustrated forever with tools that don't work as expected – completely overlooking the fact that these are not original ST products, but counterfeits.
To get the support you need, please contact the third party you purchased this product from.
For assurance of buying authentic ST products, we recommend purchasing exclusively through our official distributors, which you can find listed here: ST Official Distributors.
Regards
/Peter
2026-03-09 1:51 PM
The product you are using is a so-called Blue Pill since years only containing clones of a genuine ST product.The seemingly small price advantage quickly evaporates, because you also need an ST-LINK. If one or both contain illegal clones, as the colourful tin cans do as well, you end up frustrated forever with tools that don't work as expected – completely overlooking the fact that these are not original ST products, but counterfeits.
To get the support you need, please contact the third party you purchased this product from.
For assurance of buying authentic ST products, we recommend purchasing exclusively through our official distributors, which you can find listed here: ST Official Distributors.
Regards
/Peter
2026-03-09 2:33 PM
Yes I have a nucleo on the way but thought I'd post this in case I'm doing something wrong with the ADC.