cancel
Showing results for 
Search instead for 
Did you mean: 

ADC1 and ADC2 interleaved mode using DMA + injected

CyberNerd
Associate III

Currently I'm able to run ADC1 and ADC2 in interleaved mode using seperate (on purpose) DMA channels for ADC1 and ADC2. To start I'm using:

 

	SET_BIT(hadc2.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC slave (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled)
	HAL_DMA_Start(hadc2.DMA_Handle,(uint32_t)&hadc2.Instance->DR, (uint32_t)adc_dma_voltage_buffer,NUMBER_OF_ADC_SAMPLES); //Start ADC slave DMA
	SET_BIT(hadc1.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC master (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled)
	HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t *)adc_dma_current_buffer,NUMBER_OF_ADC_SAMPLES); //Start ADC interleaved mode

 

My handler looks like this:

 

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
    if (hadc->Instance == ADC1)
    {
        // Process the data in adc_buffer

        HAL_ADCEx_MultiModeStop_DMA(&hadc1);
        HAL_ADC_Stop(&hadc1);
        HAL_ADC_Stop(&hadc2);

        // Process data
    	long avg_val = 0;
    	for(uint16_t i = 0; i < NUMBER_OF_ADC_SAMPLES-1; i++)
    		avg_val += (adc_dma_current_buffer[i]*adc_dma_voltage_buffer[i]);

    	avg_val = avg_val/NUMBER_OF_ADC_SAMPLES;
    }

}

 

This all works fine. But now I also want to sample two different channels on ADC1 as well ADC2. Those different channels doesn't need to be stored in DMA, if I understand right, thats the case by default. The interleaved sampling will be stopped after the DMA buffer has been filled, then, after some small delay (~5ms) I was thinking to start injected sampling, but as soon as I start with this code, the ADC doesn't do anything anymore:

 

HAL_ADCEx_InjectedStart_IT(&hadc1);

 

It never fires HAL_ADC_InjectionConvCpltCallback(). Also the interleaved sampling won't start anymore, something is not correct. Hope someone can point me in the right direction.

 

1 ACCEPTED SOLUTION

Accepted Solutions
CyberNerd
Associate III

found the solution, needed HAL_ADCEx_InjectedConvCpltCallback instead of HAL_ADC_InjectionConvCpltCallback

View solution in original post

1 REPLY 1
CyberNerd
Associate III

found the solution, needed HAL_ADCEx_InjectedConvCpltCallback instead of HAL_ADC_InjectionConvCpltCallback