引脚对应图,,,,之前adc1 ADC2。配置其中一组adc单独可以正常输出,两组一起配置有一组不能正常输出,
用F302 ,大神求救。
* ADC -- battery
* PA4 --- system current ADC2_IN1
PA5 --- battery current ADC2_IN2
PA6 --- battery voltage ADC2_IN3,
PA7 --- battery temperature ADC2_IN4 --DMA2
PA1 --- robot stop current ADC1_IN2, --DMA1
static void ADC1_DMA_Config(void )
{
DMA_InitTypeDef DMA_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
// ------------------DMA Init 结构体参数 初始化--------------------------
/* Enable DMA2 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //ADC2使用DMA2 通道1
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_ADDRESS; //外设地地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertedValue1; //内存地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //读取到内存
DMA_InitStructure.DMA_BufferSize = 1; //读取数据大小
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址增加使能
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //内存地址曾使能
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_Low ; //通道高优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA_memory_to_memory使能
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA2 Channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
// ------------------ADC校准--------------------------------------------
ADC_VoltageRegulatorCmd(ADC1, ENABLE);//使能电压调节器
/* Insert delay equal to 10 ms */
Delay_ms(10);
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single); //单通道校准模式
ADC_StartCalibration(ADC1); //ADC2校准选定
while(ADC_GetCalibrationStatus(ADC1) != RESET ); //获取 ADC校准状态 (SET ?ESET)
calibration_value = ADC_GetCalibrationValue(ADC1); //ADC校准值
// -------------------ADC Common 结构体 参数 初始化------------------------
ADC_DeInit(ADC1);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式 ?????????????不知道是否对
ADC_CommonInitStructure.ADC_Clock =ADC_Clock_AsynClkMode ; //ADC_Clock_SynClkModeDiv4 ADC_Clock_AsynClkMode
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay =0; //两个采样阶段之间的延迟2个时钟;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
// -------------------ADC Init 结构体 参数 初始化--------------------------
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; //开启连续转换Disable Enable
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; //采样
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; //禁止触发检测,使用软件触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel =1; // 1个 PA1
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_2, 5, ADC_SampleTime_7Cycles5 ); //PA1 --
ADC_Cmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
/* ADC2 DMA Enable */
ADC_DMACmd(ADC1, ENABLE);
ADC_DMAConfig(ADC1, ADC_DMAMode_Circular);
/* Start ADC2 Software Conversion */
ADC_StartConversion(ADC1);
}
static void ADC2_DMA_Config(void )
{
DMA_InitTypeDef DMA_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
// ------------------DMA Init 结构体参数 初始化--------------------------
/* Enable DMA2 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); //ADC2使用DMA2 通道1
DMA_DeInit(DMA2_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC2_DR_ADDRESS; //外设地地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_ConvertedValue2; //内存地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //读取到内存
DMA_InitStructure.DMA_BufferSize = 4; //读取数据大小
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_Circular ; //循环传输格式
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //通道高优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMA_memory_to_memory使能
DMA_Init(DMA2_Channel1, &DMA_InitStructure);
/* Enable DMA2 Channel1 */
DMA_Cmd(DMA2_Channel1, ENABLE);
// ------------------ADC校准--------------------------------------------
ADC_VoltageRegulatorCmd(ADC2, ENABLE);//使能电压调节器
/* Insert delay equal to 10 ms */
Delay_ms(10);
ADC_SelectCalibrationMode(ADC2, ADC_CalibrationMode_Single); //单通道校准模式
ADC_StartCalibration(ADC2); //ADC2校准选定
while(ADC_GetCalibrationStatus(ADC2) != RESET ); //获取 ADC校准状态 (SET ?ESET)
calibration_value = ADC_GetCalibrationValue(ADC2); //ADC校准值
// -------------------ADC Common 结构体 参数 初始化------------------------
ADC_DeInit(ADC2);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式 ?????????????不知道是否对
ADC_CommonInitStructure.ADC_Clock =ADC_Clock_AsynClkMode ; //ADC_Clock_SynClkModeDiv4 ADC_Clock_AsynClkMode
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay =0; //两个采样阶段之间的延迟2个时钟;
ADC_CommonInit(ADC2, &ADC_CommonInitStructure);
// -------------------ADC Init 结构体 参数 初始化--------------------------
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; //开启连续转换Disable Enable
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; //采样
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; //禁止触发检测,使用软件触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel =4; // 4个 PA4 -- PA5 -- PA6 ---PA7
ADC_Init(ADC2, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC2,ADC_Channel_1, 1, ADC_SampleTime_7Cycles5 ); //PA4 --
ADC_RegularChannelConfig(ADC2,ADC_Channel_2, 2, ADC_SampleTime_7Cycles5 ); //PA5 --
ADC_RegularChannelConfig(ADC2,ADC_Channel_3, 3, ADC_SampleTime_7Cycles5 ); //PA6 --
ADC_RegularChannelConfig(ADC2,ADC_Channel_4, 4, ADC_SampleTime_7Cycles5 ); //PA7 --
ADC_Cmd(ADC2, ENABLE);
while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_RDY));
/* ADC2 DMA Enable */
ADC_DMACmd(ADC2, ENABLE);
ADC_DMAConfig(ADC2, ADC_DMAMode_Circular);
/* Start ADC2 Software Conversion */
ADC_StartConversion(ADC2);
}
#endif
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>