cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the ADC identifier when using DMA?

LSoll.1
Associate II

Hi!!

I am using a STM32F4 Discovery board. I am using the ADC1 and ADC2, both with DMA. I need the conditional to know which ADC was the one that finished reading data. I tried if(hadc->Instance == ADC1) but it only works when DMA is not used.

Could you help me to get the identifier of the ADC when using DMA?

This discussion is locked. Please start a new topic to ask your question.
13 REPLIES 13
LSoll.1
Associate II

Of course, here is the file

Philippe Cherbonnel
ST Employee

The problem is in HAL_ADC_MspInit(): HAL DMA handle for ADC2 is not configured

in "else if(hadc->Instance==ADC2)", there should be:

    /* ADC2 DMA Init */
    /* ADC2 Init */
    hdma_adc2.Instance = DMA2_Stream2;
    hdma_adc2.Init.Channel = DMA_CHANNEL_1;
    hdma_adc2.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_adc2.Init.MemInc = DMA_MINC_ENABLE;
    hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    hdma_adc2.Init.Mode = DMA_CIRCULAR;
    hdma_adc2.Init.Priority = DMA_PRIORITY_MEDIUM;
    hdma_adc2.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_adc2) != HAL_OK)
    {
      Error_Handler();
    }
 
    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc2);

with hdma_adc2 declared in the same way as hdma_adc1 (global variable).

If you started from CubeMX, then something is missing in the GUI configuration.

Best regards

Philippe

LSoll.1
Associate II

I understand, the ADC2 wasn't configured with DMA because I wasn't using it. Remove the ADC 2 configuration from the GUI.

My question now is, how should I build the conditional? because

if(hadc->Instance == ADC1) doesn't work, I'm doing it wrong and it's not clear to me why.

Thank you very much for your time!

LSoll.1
Associate II

It worked!!! I had to set it up like this:

if (hadc->DMA_Handle->Instance == DMA2_Stream0){

Thank you very much to all!!