|
void ADC_Configuration(void) {
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //指定转换工作在扫描(多信道)模式
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//指定转换工作在连续模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //由软件控制开始转换,而不是外部触发器。
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//ADC数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1; //指定将要进行转换的ADC 信道号1
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_13Cycles5); //ADC1 regular channels configuration
ADC_DMACmd(ADC1, ENABLE); //使能ADC1 DMA请求
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //配置
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC2, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_13Cycles5); /* ADC2 regular channels configuration */
ADC_ExternalTrigConvCmd(ADC2, ENABLE); /* Enable ADC2 external trigger conversion */
ADC_DMACmd(ADC2, ENABLE);
ADC_Cmd(ADC1, ENABLE); //使能ADC1外围模块
ADC_TempSensorVrefintCmd(ENABLE); //Enable Vrefint channel17
ADC_ResetCalibration(ADC1); //重置ADC1校准寄存器
while(ADC_GetResetCalibrationStatus(ADC1)); //等待ADC1校准寄存器准备就绪
ADC_StartCalibration(ADC1); //开始ADC1校准过程
while(ADC_GetCalibrationStatus(ADC1)); //等待ADC1校准过程结束
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 */
ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* Start ADC1 Software Conversion */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1)); /* Test on DMA1 channel1 transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC1); /* Clear DMA1 channel1 transfer complete flag */
} |
|