2016-03-19 05:21 AM
I am working with AVRs for almost last 3 years and decided to buy a stm32 nucleo boards to have some fun with ARM and bought STM32L476RG nucleo board.I started to write code in Keil MDK-5 with the help of Hal drivers from STM32Cube MX.I coded for some Blinky and Usart successfully.But as i moved to ADC,i faced a strange problem.From the board schematics,i found that the MCU is using 3v3 external Vref.I measured with a multimeter and found 3.29v.I then coded a program to display the ADC read value in single conversation mode via Usart.As the ADC of the STM32 is 12 bit,it should return 4095 while reading 3.3v.But whenever i am connecting PA0(Analog ADC pin 5) to 3.3v,it is returning value between 4025 to 4028.I tried to average of 100 results but got same output.Also i tried with different clock speeds but had no luck.
My question is if the error(typically 1.63% to 1.71%) is normal or if my adc unit is faulty or am i missing something????I found very little help about L476G as the controller is very new.Please reply guys...
#stm32l4762016-03-20 12:25 PM
2016-03-21 02:26 AM
Thanks a lot for your reply.But as you suggested, I have already tried more than 5 different type of programs with (slower clock speeds also) but had no luck.
Whenever i connect the PA0 to ground,it is clearly showing 0.But whenever i connect it to 3.3v,it reads a value somewhere between 4025 to 4028.I can't have the clue if the ADC is erroneous or i am missing something.Please suggest what to do next.2016-03-21 11:58 AM
Though i found a solution,Please tell me if it is correct or not....
Every time,i run a calibration before any measurement and find the calibration factor and set the value and then start ADC like below. uint32_t Calibration_Factor; HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED); Calibration_Factor=HAL_ADCEx_Calibration_GetValue(&hadc1,ADC_SINGLE_ENDED); HAL_ADCEx_Calibration_SetValue(&hadc1,ADC_SINGLE_ENDED,Calibration_Factor); HAL_ADC_Start(&hadc1); Now my ADC is returning stable value of 4095/4094 for reading of 3.3v.