AnsweredAssumed Answered

How do you configure DMA1 with multiple ADC channels with different buffer sizes?

Question asked by mullane.liam.005 on Sep 7, 2017
Latest reply on Sep 8, 2017 by mullane.liam.005

Hi

I'm using a STM32F103ZE

I'm trying to configure DMA1 with ADC1 Channels 12 & 16.
The code below works i.e. when the DMA flags the DMA_Buffer contains 800 samples,

   400 for Channel_12 and

   400 for Channel_16
However I only need a 4 samples for Channel_16
Is there a way to configure the DMA1 to retrieve 400 samples on Channel_12 and 4 samples on Channel_16 ?


Thanks
Liam

 

 

#define BUFF_SIZE 800
uint32_t DMA_Buffer[BUFF_SIZE];

 

void ConfigConductivityADC (void)
{

ADC_InitTypeDef ADC_InitStructure;
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
ADC_DeInit(ADC1);
// ADC1 configuration
ADC_InitStructure.ADC_Mode= ADC_Mode_RegSimult;
ADC_InitStructure.ADC_ScanConvMode= ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_DataAlign= ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel= 2;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_TempSensorVrefintCmd(ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 2, ADC_SampleTime_239Cycles5);
ADC_ExternalTrigConvCmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}

void ConfigConductivityDMA(void)
{

DMA_InitTypeDef DMA_InitStructure;
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr=ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)DMA_Buffer;
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize=BUFF_SIZE;
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority=DMA_Priority_High;
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
}

Outcomes