cancel
Showing results for 
Search instead for 
Did you mean: 

Setting interrupt ADC conversion is complete using HAL

borisbritwa13
Associate III
Posted on August 05, 2015 at 11:37

STM32F407VG

When Interrupt function looks like this:

void ADC_IRQHandler(void)

{

adc=HAL_ADC_GetValue(&hadc1);

 HAL_ADC_IRQHandler(&hadc1);

  HAL_ADC_Start_IT(&hadc1);

}

Everything works well.

But when I want to do the ADC conversion one by one.(  hadc1.Init.ContinuousConvMode = ENABLE;)

void ADC_IRQHandler(void)

{

adc=HAL_ADC_GetValue(&hadc1);

 HAL_ADC_IRQHandler(&hadc1);

 // HAL_ADC_Start_IT(&hadc1);

}

 OVR bit in the SR register is set and ADC is not working.

As the end of conversion, we get to ADC_IRQHandler, collect our data .All right. Bit OVR shall not be installed so as we all do in time.

I have to constantly reset the OVR bit or make the setting(hadc1.Init.EOCSelection = EOC_SEQ_CONV;) and then the OVR bit

will not be installed.

ADC conversion

again

works well.

Why OVR bit is set?

#discovery #adc #stm32f4
15 REPLIES 15
borisbritwa13
Associate III
Posted on August 09, 2015 at 18:51

https://youtu.be/BXk-IkVoBXQ

�?t the end of

the

video conversion

 

one by one with

interrupt

Thanks to all

for the help

!!!!

keaven
Associate II
Posted on August 10, 2015 at 17:38

''HAL_ADC_ConvCpltCallback could be implemented in the user file''  

how to use it in main()

?

Simply add it to your source file and add your code to it.  Those functions are  ''weak'' type they are like a virtual type function.  All callbacks of HAL library works that way.

RomainR.
ST Employee
Posted on August 11, 2015 at 10:34

britwa.boris

.

Could you provide

your

ADC

Setup function

?

As explained

Keaven

,

HAL_ADC_ConvCpltCallback

function must be

implemented in

your main program

after the

main ()

your

ADC

interrupt

function should

look exactly like

:

ADC_IRQHandler

void

(void)

{

  

HAL_ADC_IRQHandler

(

&

AdcHandle

)

;

}

I suggest you

take a

look

at the

example

program in the

repository

CubeMx

C: \

Users \

username \

STM32Cube

\

Repository

\

STM32Cube_FW_F4_V1.7.0

\ Projects

\

STM32446E_EVAL

\ Examples

\

ADC

Good luck

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.

borisbritwa13
Associate III
Posted on August 11, 2015 at 18:42

rrom

catch

/* ADC1 init function */

void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

    */

  hadc1.Instance = ADC1;

  hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

  hadc1.Init.Resolution = ADC_RESOLUTION12b;

  hadc1.Init.ScanConvMode = DISABLE;

  hadc1.Init.ContinuousConvMode =ENABLE;

  hadc1.Init.DiscontinuousConvMode = DISABLE;

  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.NbrOfConversion = 1;

  hadc1.Init.DMAContinuousRequests = DISABLE;

  hadc1.Init.EOCSelection = EOC_SINGLE_CONV;

  HAL_ADC_Init(&hadc1);

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

    */

  sConfig.Channel = ADC_CHANNEL_1;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

}

''HAL_ADC_ConvCpltCallback could be implemented in the user file''-

well

understood.

RomainR.
ST Employee
Posted on August 12, 2015 at 08:45

I suggest you

to

follow the

recommendations

of Clive1

.

A

 

very aggressive

timming

perspective

thus

he goes into

o

verrun

e

rror.

What

conversion

rate

do you need?

Maybe

you should

trigger your

ADC

conversion with

a timer

and capture

the result in your

HAL_ADC_ConvCpltCallback

()

Or

use DMA

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.

borisbritwa13
Associate III
Posted on August 12, 2015 at 19:39

I

wrote above

that everything works

topic is closed!!!!

https://youtu.be/BXk-IkVoBXQ

�?t the end of

the

video conversion

 

one by one with

interrupt