2024-08-08 05:52 AM - edited 2024-08-08 05:53 AM
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.
Solved! Go to Solution.
2024-08-08 07:40 AM
found the solution, needed HAL_ADCEx_InjectedConvCpltCallback instead of HAL_ADC_InjectionConvCpltCallback
2024-08-08 07:40 AM
found the solution, needed HAL_ADCEx_InjectedConvCpltCallback instead of HAL_ADC_InjectionConvCpltCallback