以下是我项目中的片段,配置完成后,请使用软件触发,并声明一个 u16 ADC_ConvertedValueTab[6]数组。触发后等待DMA完成后就可以读数据了。 void ADC_Config(void) { ADC_DeInit(ADC1); ADC_DeInit(ADC2); ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 3; ADC_Init(ADC1, &ADC_InitStructure); ADC_Init(ADC2, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 2, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 3, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 2, ADC_SampleTime_71Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 3, ADC_SampleTime_71Cycles5); //55 ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 DMA */ ADC_ResetCalibration(ADC1); /* Enable ADC1 reset calibaration register */ while(ADC_GetResetCalibrationStatus(ADC1)){} /* Check the end of ADC1 reset calibration register */ ADC_StartCalibration(ADC1); /* Start ADC1 calibaration */ while(ADC_GetCalibrationStatus(ADC1)){} /* Check the end of ADC1 calibration */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 */ ADC_ResetCalibration(ADC2); /* Enable ADC2 reset calibaration register */ while(ADC_GetResetCalibrationStatus(ADC2)){} /* Check the end of ADC2 reset calibration register */ ADC_StartCalibration(ADC2); /* Start ADC2 calibaration */ while(ADC_GetCalibrationStatus(ADC2)){} /* Check the end of ADC2 calibration */ }
void DMA_Config(void) { DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 3; 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_VeryHigh; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); DMA_Cmd (DMA1_Channel1, ENABLE); DMA_ITConfig(DMA1_Channel1, DMA_IT_TC,DISABLE);/* Enable DMA channel1 */
/* DMA1 Channel4 (triggered by USART1 Tx event) Config */ DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)COMMtxd; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 64; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel4, &DMA_InitStructure); DMA_Cmd (DMA1_Channel4, ENABLE); DMA_ITConfig(DMA1_Channel4, DMA_IT_TC,ENABLE);/* Enable DMA channel4 */ } |