Skip to main content
boris239955_stm1_st
Associate II
August 3, 2016
Question

STM32F746, ADC

  • August 3, 2016
  • 2 replies
  • 678 views
Posted on August 03, 2016 at 08:43

Hello, can someone to explain to me what happen when you use 8 channels on ADC, and use DMA. How DMA take ready sample from data register. I think when first channel is ready, dma take it first, after that second, third to the eight, but I'm not sure

    This topic has been closed for replies.

    2 replies

    Nesrine M_O
    Associate
    August 3, 2016
    Posted on August 03, 2016 at 10:18

    Hi s.boris,

    Please have a look to the Data management section in your related reference manual.

    -Syrine-

    boris239955_stm1_st
    Associate II
    August 5, 2016
    Posted on August 05, 2016 at 10:35

    Hello, I run the ADC with DMA but there is a problem. DMA buffer is not refresh completely after the first run, I use two channels. I start ADC on every 100us, and this part is working. This is the code that is not working

    
    static void hw_adc_3_dma_init(DMA_HandleTypeDef* _hdma, ADC_HandleTypeDef* _hadc)
    
    {
    
    __HAL_RCC_DMA2_CLK_ENABLE();
    
    
    _hdma->Instance = DMA2_Stream0; // Set which DMA and stream will be init
    
    _hdma->Init.Channel = DMA_CHANNEL_2; // Set DMA channel
    
    _hdma->Init.Direction = DMA_PERIPH_TO_MEMORY; // Set DMA data transfer direction
    
    _hdma->Init.PeriphInc = DMA_PINC_DISABLE; // Set DMA peripheral increment mode
    
    _hdma->Init.MemInc = DMA_MINC_ENABLE; // Set DMA memory increment mode
    
    _hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; // Set DMA peripheral data size 16 bit
    
    _hdma->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; // Set DMA memory data size 16 bit
    
    _hdma->Init.Mode = DMA_NORMAL; // Set DMA mode. Should be one shot
    
    _hdma->Init.Priority = DMA_PRIORITY_MEDIUM; // Set DMA priority
    
    _hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; // Set DMA direct mode
    
    _hdma->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; // Set DMA FIFO threshold lvl
    
    _hdma->Init.MemBurst = DMA_MBURST_SINGLE; // Set DMA memory burst
    
    _hdma->Init.PeriphBurst = DMA_PBURST_SINGLE; // Set DMA peripheral burst
    
    
    HAL_DMA_Init(_hdma); // Init DMA with selected value of registers
    
    
    __HAL_LINKDMA(_hadc, DMA_Handle, *_hdma); // Associate init DMA handle to ADC DMA
    
    
    // Set DMA priority
    
    // When 2 interrupts have same preemption priority, then he one who has higher sub priority will be execute first.
    
    // If both interrupts both have same preemption priority and sub priority, the one comes first will be execute first
    
    HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 1, 0);
    
    HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
    
    }
    
    
    void hw_adc_3_start()
    
    {
    
    HAL_ADC_Start_DMA(&hadc3, (U32 *)&adc_3_convert_value[0],150); 
    
    }
    
    
    void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* _handler)
    
    {
    
    if (_handler == &hadc1)
    
    {
    
    __HAL_ADC_DISABLE(&hadc1);
    
    hw_adc_process(adc_1, &adc_status_1);
    
    }
    
    else if (_handler == &hadc2)
    
    {
    
    __HAL_ADC_DISABLE(&hadc2);
    
    hw_adc_process(adc_2, &adc_status_2);
    
    }
    
    else if (_handler == &hadc3)
    
    {
    
    __HAL_ADC_DISABLE(&hadc3);
    
    hw_adc_process(adc_3, &adc_status_3);
    
    }
    
    }