2021-04-10 03:41 PM
Hey, I'm trying to get some temperature readings from LM35 sensor and I'm using "blue pill" for this little project and of course ADC. The problem is that I am getting wrong readings, approximately half of the real value. I know that the sensor is good because I tested it with arduino nano and well it gave me right values.
void ADC()
{
error= HAL_ADC_Start(&hadc1);
if(error!=HAL_OK)
{
i=1;
}
error=HAL_ADC_PollForConversion(&hadc1,1);
if(error!=HAL_OK)
{
i=2;
}
i=3;
Adc_Value = HAL_ADC_GetValue(&hadc1);
Reiksme=(Adc_Value*3.3)/(4096*0.01);
HAL_Delay(1000);
}
here is my little function to get those values. Any ideas why it doesn't work on this mcu?
Solved! Go to Solution.
2021-04-12 02:15 AM
Proposals:
And please also check VCC, as you are referring to a fixed value of 3.3V when calculating, e.g. by measuring the internal reference voltage.
2021-04-12 12:39 AM
I assume you get the supply voltage of the LM35 from VCC of the STM32F103, right?
The LM35 is a analoge centigrade temperature sensor requiring a supply voltage of 4...30V. It will work if you supply it with 5V like you did with Arduino.
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Good luck!
/Peter
2021-04-12 12:47 AM
Yeah, I'm using supply voltage from my STM32. I tried connecting different source of 5V but it still does not work properly. I tried measuring signal voltage with a multimeter and got correct voltages ( around 200 mV in 20 °C temperature) so I it's got to be mcu problem with converting.
2021-04-12 02:15 AM
Proposals:
And please also check VCC, as you are referring to a fixed value of 3.3V when calculating, e.g. by measuring the internal reference voltage.