cancel
Showing results for 
Search instead for 
Did you mean: 

HAL ADC Generic Driver - STM32Cube

ee06091
Associate III
Posted on October 11, 2017 at 22:16

Hi,

I'm very confused on how to use the HAL ADC Generic Driver. I configure the ADC using STM32Cube with all the default settings.

Now I want to start the ADC and handle the interrupt. Looking into the

http://www.st.com/content/ccc/resource/technical/document/user_manual/2f/77/25/0f/5c/38/48/80/DM00122015.pdf/files/DM00122015.pdf/jcr:content/translations/en.DM00122015.pdf

 I read:

1 - ADC conversion by interruption:

1.1 - Activate the ADC peripheral and start conversions using function HAL_ADC_Start_IT()

1.2 - Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() (this function must be implemented in user program)

1.3 - Retrieve conversion results using function HAL_ADC_GetValue() Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop_IT()

However STM32Cube had generated a IRQ Handler for adc on stm32f0xx_it.c:

/**

*

@brief

This

function

handles

ADC

interrupt.

*/

void

ADC1_IRQHandler(

void

)

{

   

/*

USER

CODE

BEGIN

ADC1_IRQn

0

*/

   

/*

USER

CODE

END

ADC1_IRQn

0

*/

   

HAL_ADC_IRQHandler(&hadc);

   

/*

USER

CODE

BEGIN

ADC1_IRQn

1

*/

   

/*

USER

CODE

END

ADC1_IRQn

1

*/

}

My questions are:

1 - Why there is a HAL_ADC_IRQHandler() inside the ADC1_IRQHandler?

2 - Should I use this function to write my code and get adc value?

3 - Should I implement HAL_ADC_ConvCpltCallback() ?

#stm32-adc-interrupt
1 ACCEPTED SOLUTION

Accepted Solutions
Zt Liu
Senior III
Posted on October 12, 2017 at 05:15

1 - Why there is a HAL_ADC_IRQHandler() inside the ADC1_IRQHandler?

      This HAL_XXX_IRQHandler() often do some jobs like set/reset flags, updating Handle status or state, and 

      jump to user callback functions.

2 - Should I use this function to write my code and get adc value?

3 - Should I implement HAL_ADC_ConvCpltCallback() ?

      you will implement your codes in this weak defined function HAL_XXX_XXXCallbacks and get you ADC value.

Good Luck!

View solution in original post

4 REPLIES 4
Zt Liu
Senior III
Posted on October 12, 2017 at 05:15

1 - Why there is a HAL_ADC_IRQHandler() inside the ADC1_IRQHandler?

      This HAL_XXX_IRQHandler() often do some jobs like set/reset flags, updating Handle status or state, and 

      jump to user callback functions.

2 - Should I use this function to write my code and get adc value?

3 - Should I implement HAL_ADC_ConvCpltCallback() ?

      you will implement your codes in this weak defined function HAL_XXX_XXXCallbacks and get you ADC value.

Good Luck!

Dean Perry
Associate III
Posted on October 12, 2017 at 05:36

See comment by

Liu.Zhitai

about __weak functions in HAL, they're used in several places.

I have just done my first STM32 ADC project and I will add that if you expect to be doing continuous conversions then you probably want to look at DMA. The conversion complete interrupt when doing continuous conversions is very very frequent even with the longest conversion time and lots of channels.

ee06091
Associate III
Posted on October 12, 2017 at 18:13

Thank you both for the advice.

Posted on October 12, 2017 at 22:19

I implemented a continuous ADC conversion using DMA for the ADC 3 port of the SensorTile. The pin is PC2. I was able to get the voltage readings from this ADC pin when the sensortile is hooked up to the STLCX01V1 - eval board for the sensortile. But when I solder the sensortile on the cradle board, STLCR01V1- I dont see any readings. It comes as 0. Note that, the ADC value comes as zero.

Do you know if there is a need of setting requirement to make the ADC reading available on the cradle board? I think that there is something I am missing like HAL_PWREx_PVM3(). Tried this, didn't work.

Did your ADC sensing work on the cradle board?