本帖最后由 gregrgr 于 2021-5-19 08:38 编辑
GPIO_InitType GPIO_InitStructure;
ADC_InitType ADC_InitStructure;
DMA_InitType DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_DMA1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_ADC1, ENABLE);
RCC_AHBPeriphClockCmd(AT32_ADC_GPIO_RCC_CLK, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = AT32_ADC_LDR_PIN | AT32_ADC_VBUS_PIN | AT32_ADC_ACC_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_Init(AT32_ADC_GPIO, &GPIO_InitStructure);
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_Reset(DMA1_Channel1);
DMA_DefaultInitParaConfig(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->RDOR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab;
DMA_InitStructure.DMA_Direction = DMA_DIR_PERIPHERALSRC;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;
DMA_InitStructure.DMA_PeripheralDataWidth = DMA_PERIPHERALDATAWIDTH_HALFWORD;
DMA_InitStructure.DMA_MemoryDataWidth = DMA_MEMORYDATAWIDTH_HALFWORD;
DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR;
DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_ChannelEnable(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanMode = ENABLE;
ADC_InitStructure.ADC_ContinuousMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrig = ADC_ExternalTrig_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NumOfChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_13_5);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 2, ADC_SampleTime_13_5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 2, ADC_SampleTime_13_5);
ADC_ExternalTrigConvCtrl(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACtrl(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Ctrl(ADC1, ENABLE);
AT32F421 ADC DMA 多通道采集数据干扰,采集通道1 的时候,通道2的数据也跟着变 |