cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 autostart ADC1 (Scan, 4 channel) w/o HAL_ADC_Start_DMA() ?

PRenn.1
Associate III

I'm searching for super coding comfort in CubeIDE.   Currently TIM2 resets/updates.
In HAL_TIM_PeriodElapsedCallback()  I "manually" start HAL_ADC_Start_DMA() the Scan conversion of four channels and have the four results shipped into my progs memory, via DMA.   Works like a charm.


But there is the mighty diagram  (Fig.31) on p.213 of the STM32F411CEU6  reference manual, 
clearly showing that ther are alternatives to starting the ADC manually via software.  
Among a lot of options there is TIM2_TRGO or TIM2_CHx configurable as ADC trigger input.

So,  is the following possible:
1) TIM2 loops indefinitely at a speed configured by me after being started once in main().
2) At every interation TIM2 triggers the start of  the ADC (HOW?).
3) The ADC is configured to convert 4 channels.
4) The ADC is configuired to ship the result of every conversion to my memory via DMA.

Currently I've no idea how to click / dropdwon  CubeIDE to get 2)  working.

The result would be very cool:
no callbacks at all,  all steps in that process chain done automagically,
the software coder simply has to look at DMA destination buffers, and do his thing.

4 REPLIES 4
PRenn.1
Associate III

Nice examples, thx!


I found TIM2 settings :

/* Set timer the trigger output (TRGO) */
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_UPDATE);
/* Enable counter */
LL_TIM_EnableCounter(TIM2);

sounds familiar, but directly via the LowLevel interface routines.  TIM2_TRGO UPDATE is set.


There are ADC Setting, too:
/* Set ADC group regular trigger source */
LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_EXT_TIM2_TRGO);

So the TIM2 Output is set to TRGO_UPDATE and the ADC is set to have TIM2_TRGO as trigger source.
=> Exaclty what I tried in CubeIDE (CubeMX confgiured, I think) but no data delivered.

Question is what / where to click in CubeIDE HAL-config to setup both
TIM2_TRGO_UPDATE and ADC trigger_source TIM2_TRGO 

PRenn.1
Associate III

There are only three HAL_ADC_Start routines:  polling, IT (Interrupt) and DMA. 
Somehow I'm missing "HAL_ADC_Start_trigger"   or "HAL_ADC_Start_TIM2TRGO" .

If I comment out the HAL_ADC_Start_DMA in the TIM2 interrupt routine, and only do one single HAL_ADC_Start_DMA right befor the "main loop" 
I get  exactly one setup of conversions, and nothing exlse although the TIM2 happily counter and overflows etc

There is no such option like set both. I even can't find to set TIM2_TRGO in the timer's sub-menu tabs. Regarding setting linked two lines timer-trgo And adc-trigger, feature wouldn't make sense if more than one timer has active trigger line or many adc linked to different triggers, so this  linkage delegated to programmer, to set it "manually".