2017-10-11 01:16 PM
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
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-interruptSolved! Go to Solution.
2017-10-11 08:15 PM
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!
2017-10-11 08:15 PM
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!
2017-10-11 08:36 PM
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.
2017-10-12 09:13 AM
Thank you both for the advice.
2017-10-12 03:19 PM
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?