Skip to main content
DSimp.1
Associate III
April 10, 2021
Solved

STM32F103xC and LM35 wrong readings

  • April 10, 2021
  • 1 reply
  • 2707 views

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?

This topic has been closed for replies.
Best answer by Peter BENSCH

Proposals:

  • please check AN2834
  • please check your ADC settings, e.g. clock, sampling time
  • calibrate the ADC using a HAL_ADCEx_Calibration_Start
  • test an increased timeout of e.g. 10ms by HAL_ADC_PollForConversion(&hadc1,10);

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.

1 reply

Peter BENSCH
Technical Moderator
April 12, 2021

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DSimp.1
DSimp.1Author
Associate III
April 12, 2021

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.

Peter BENSCH
Peter BENSCHBest answer
Technical Moderator
April 12, 2021

Proposals:

  • please check AN2834
  • please check your ADC settings, e.g. clock, sampling time
  • calibrate the ADC using a HAL_ADCEx_Calibration_Start
  • test an increased timeout of e.g. 10ms by HAL_ADC_PollForConversion(&hadc1,10);

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.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.