cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F334, Use HAL lib to configure ADC with EXTI 11 as trigger + DMA

Jordi Becares
Associate II

Hi,

I'm trying to configure ADC2 to get data via DMA with external trigger interrupt.

I'm usign StCube framework.

I get read data via DMA with request capture via software with any problem, but I need to synchronise the external trigger with start ADC via HW (If i capture the external interrupt and after enable ADC, I have a big delay of 4us)

HAL_ADC_Start_DMA(&hadc2, (uint32_t*)buffDMA, 100)

But, I don't know how to start DMA when config EXTI

Here, code to config ADC with EXTI line 11

/* ADC2 init function */
static void MX_ADC2_Init(void)
{
 
  ADC_ChannelConfTypeDef sConfig;
 
    /**Common config 
    */
  hadc2.Instance = ADC2;
  hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  hadc2.Init.Resolution = ADC_RESOLUTION_8B;
  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc2.Init.ContinuousConvMode = ENABLE;
  hadc2.Init.DiscontinuousConvMode = DISABLE;
  hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
  hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_EXT_IT11;
  hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc2.Init.NbrOfConversion = 1;
  hadc2.Init.DMAContinuousRequests = DISABLE;
  hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  hadc2.Init.LowPowerAutoWait = DISABLE;
  hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  if (HAL_ADC_Init(&hadc2) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
  
    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

Now, how start device to get data via DMA when interrupt in EXTI_11 is fired?

Thanks

Jordi

0 REPLIES 0