2017-11-28 07:53 AM
Dear all,
I have configured ADC - 1 channel with DMA to retrieve data. It all works fine.
Now, I am trying to use the same ADC (ADC1, DMA2_Stream0) to use 2 channels (channel 12 and 13).
uint16_t ADC_Value[2] = {0,0}; //the user variable for retrieving ADC data from 2 channels
DMA_InitStructure.DMA_Channel =DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)&ADC1->DR; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&ADC_Value; DMA_InitStructure.DMA_DIR =DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize =2; // increase the buffer size for multi-channels DMA_InitStructure.DMA_PeripheralInc =DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc =DMA_MemoryInc_Enable; //Enabling the memory increment DMA_InitStructure.DMA_PeripheralDataSize =DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize =DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode =DMA_Mode_Circular; DMA_InitStructure.DMA_Priority =DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode =DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold =DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst =DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst =DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); DMA_Cmd(DMA2_Stream0, ENABLE);/* ADC1 Init ****************************************************************/
ADC_InitStructure.ADC_Resolution =ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode =ENABLE; // Single channel or Multiple channels (ENABLE) ADC_InitStructure.ADC_ContinuousConvMode =ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_None; //Software Conversion ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign =ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion =2; // INCREASE for multiple channels ADC_Init(ADC1, &ADC_InitStructure);In the main(),
while(1)
{
printf('%d,%d,%d\r\n',ADC_Value[0],ADC_Value[1],myCounter);
}
Firstly, I'd like to know if my settings are correct. And secondly, Can someone explain me how exactly the result variable (array) is filled with ADC data from the DR?
Thanks a lot.
#adc-dma-stm32f4 #adc2017-11-28 08:44 AM
Doesn't the RM describe the process? One 16-bit word at a time, triggered by EOC of channel.
Variable should be volatile, DMA changes outside execution flow.
You'd need two ADC to sample at the same time, then you'd use CDR (Common Data Register), which basically combines ADC1->DR and ADC2->DR into a singular 32-bit read.