cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ADC_PollForConversion vs HAL_ADC_GetValue

skon.1
Senior

Hello, 

I see ADC examples that use the following functions:

1.HAL_ADC_PollForConversion.

2.HAL_ADC_GetValue.

Questions:

a. What's the difference between both functions ?

b. In my application I simply want to get the ADC voltage when a user sends a command. What function should I use ?

4 REPLIES 4

Hi, HAL_ADC_PollForConversion start the conversion in the selected channel and keep waiting till the conversion is done, after that you must to call HAL_ADC_GetValue to store the conversion value, you need to use both functions in this order. So, in you application just catch the command and call them both functions.

TDK
Guru

Recommend usage of HAL functions is found in the source file.

You can also inspect the code. HAL_ADC_GetValue merely reads the DR register. You will need to start and wait for the conversion using HAL_ADC_PollForConversion.

                       *** Execution of ADC conversions ***
  ==============================================================================
  [..]  
  (#) ADC driver can be used among three modes: polling, interruption,
      transfer by DMA.    
 
     *** Polling mode IO operation ***
     =================================
     [..]    
       (+) Start the ADC peripheral using HAL_ADC_Start() 
       (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
           user can specify the value of timeout according to his end application      
       (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
       (+) Stop the ADC peripheral using HAL_ADC_Stop()

If you feel a post has answered your question, please click "Accept as Solution".

Thanks,

Where can I get this file ?

TDK
Guru

> Where can I get this file ?

It should be included in your project directory somewhere.

The latest version is also available here:

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c

If you feel a post has answered your question, please click "Accept as Solution".