关于STM32F207内部3个ADC+DMA同时采集的问题

2019-03-23 18:13发布

在使用STM32F207的ADC时,需要同时使用3个ADC独立进行采集,并且分别使用各自的DMA通道保存一段采集波形到各自的buffer中,遇到的现象是:
1)单独使用ADC1/2/3都可以完成采集过程,数据与输入波形吻合;
2)同时使用ADC1+ADC3或者ADC2+ADC3,两通道的数据波形吻合;
3)同时使用ADC1+ADC2或者ADC1+ADC2+ADC3,采集结果显示ADC2和ADC3通道的数据正常,但是ADC1数据出现6~7个点重复,如图
QQ截图20160517093304.jpg
请问,有人遇到过这种情况吗?或者有可以参考的3通道ADC+DMA并行采集的代码?非常感谢!
另附配置参数:
// ADC Common Init
  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;        //60M/2=30M
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;//simultaneous triple mode.
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInit(&ADC_CommonInitStructure);

// ADC Init
        ADC_StructInit(&ADC_InitStructure);
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfConversion = 1;//scan channel number.
  ADC_Init(ADC2, &ADC_InitStructure);
  ADC_Init(ADC3, &ADC_InitStructure);
  ADC_Init(ADC1, &ADC_InitStructure);

// Enable DMA request after last transfer
  ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
  ADC_DMARequestAfterLastTransferCmd(ADC2, ENABLE);
  ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);
  ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);

//DMA configuration
  DMA_StructInit(&DMA_InitStructure);
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;         
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC8;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Cmd(DMA2_Stream0, DISABLE);
                DMA_DeInit(DMA2_Stream0);
                DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
                DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;
                DMA_InitStructure.DMA_Channel = DMA_Channel_0;
                DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
                DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Buffer_A;
                DMA_Init(DMA2_Stream0, &DMA_InitStructure);
                DMA_Cmd(DMA2_Stream0, ENABLE);       
                ADC_DMACmd(ADC1, ENABLE);
                ADC_Cmd(ADC1, ENABLE);
                ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);
DMA_Cmd(DMA2_Stream2, DISABLE);
                DMA_DeInit(DMA2_Stream2);
                DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
                DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;
                DMA_InitStructure.DMA_Channel = DMA_Channel_1;
                DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC2_DR_Address;
                DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Buffer_B;
                DMA_Init(DMA2_Stream2, &DMA_InitStructure);
                DMA_Cmd(DMA2_Stream2, ENABLE);       
                ADC_DMACmd(ADC2, ENABLE);
                ADC_Cmd(ADC2, ENABLE);
                ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);

DMA_Cmd(DMA2_Stream1, DISABLE);
                DMA_DeInit(DMA2_Stream1);
                DMA_InitStructure.DMA_Priority = DMA_Priority_High;
                DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;
                DMA_InitStructure.DMA_Channel = DMA_Channel_2;
                DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_Address;
                DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Buffer_C;
                DMA_Init(DMA2_Stream1, &DMA_InitStructure);
                DMA_Cmd(DMA2_Stream1, ENABLE);       
                ADC_DMACmd(ADC3, ENABLE);
                ADC_Cmd(ADC3, ENABLE);
                ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 1, ADC_SampleTime_3Cycles);

//main -- start sampling
ADC_SoftwareStartConv(ADC1);
                ADC_SoftwareStartConv(ADC2);
                ADC_SoftwareStartConv(ADC3);
                while(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_TCIF0)==RESET);
                while(DMA_GetFlagStatus(DMA2_Stream2,DMA_FLAG_TCIF0)==RESET);
                while(DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_TCIF0)==RESET);
                ADC_Cmd(ADC1, DISABLE);
                ADC_Cmd(ADC3, DISABLE);
                ADC_Cmd(ADC2, DISABLE);


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。