已经把ADC1的16个通道(7寸屏占了一个PB1)全用上了(扫描模式,连续转换)还是差一个,所以使用ADC3的通道4,但是一使用ADC3数据就全都不对了,不知道扫描原因?
[mw_shl_code=c,true]void ADCChannel_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOF|RCC_APB2Periph_ADC1|RCC_APB2Periph_ADC3,ENABLE);
//设置引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//模拟输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);//PC0 PC1 PC2 PC3 PC4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOF,&GPIO_InitStructure);
//设置ADC1
ADC_DeInit(ADC1);//复位ADC1,ADC1的所有寄存器恢复缺省值
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//设置六分频,ADC的最大频率不要超过14M,否则精度下降
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;//ADC独立模式
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=15;//顺序进行规制转换的ADC通道的数目
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_239Cycles5);//ADC1,通道0,采样顺序为1,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,2,ADC_SampleTime_239Cycles5);//ADC1,通道1,采样顺序为2,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_2,3,ADC_SampleTime_239Cycles5);//ADC1,通道2,采样顺序为3,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_3,4,ADC_SampleTime_239Cycles5);//ADC1,通道3,采样顺序为4,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_4,5,ADC_SampleTime_239Cycles5);//ADC1,通道4,采样顺序为5,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_5,6,ADC_SampleTime_239Cycles5);//ADC1,通道5,采样顺序为6,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_6,7,ADC_SampleTime_239Cycles5);//ADC1,通道6,采样顺序为7,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_7,8,ADC_SampleTime_239Cycles5);//ADC1,通道7,采样顺序为8,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_8,9,ADC_SampleTime_239Cycles5);//ADC1,通道10,采样顺序为11,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_10,10,ADC_SampleTime_239Cycles5);//ADC1,通道10,采样顺序为11,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_11,11,ADC_SampleTime_239Cycles5);//ADC1,通道11,采样顺序为12,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_12,12,ADC_SampleTime_239Cycles5);//ADC1,通道12,采样顺序为13,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_13,13,ADC_SampleTime_239Cycles5);//ADC1,通道13,采样顺序为14,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_14,14,ADC_SampleTime_239Cycles5);//ADC1,通道14,采样顺序为15,采样周期239.5
ADC_RegularChannelConfig(ADC1,ADC_Channel_15,15,ADC_SampleTime_239Cycles5);//ADC1,通道15,采样顺序为16,采样周期239.5
//ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
ADC_Cmd(ADC1,ENABLE);//使能ADC
ADC_ResetCalibration(ADC1);//开启复位校准
while(ADC_GetResetCalibrationStatus(ADC1));//等待复位校准结束
ADC_StartCalibration(ADC1);//开启ADC校准
while(ADC_GetCalibrationStatus(ADC1));//等待ADC校准结束
ADC_DeInit(ADC3);//复位ADC1,ADC1的所有寄存器恢复缺省值
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;//ADC独立模式
ADC_InitStructure.ADC_ScanConvMode= DISABLE;//扫描模式
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通道的数目
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC3,ADC_Channel_4,1,ADC_SampleTime_239Cycles5);//ADC1,通道0,采样顺序为1,采样周期239.5
ADC_Cmd(ADC3,ENABLE);//使能ADC
ADC_ResetCalibration(ADC3);//开启复位校准
while(ADC_GetResetCalibrationStatus(ADC3));//等待复位校准结束
ADC_StartCalibration(ADC3);//开启ADC校准
while(ADC_GetCalibrationStatus(ADC3));//等待ADC校准结束
}
[/mw_shl_code]
---------------------------------
啥原因啊?新代码能发上来吗?
一周热门 更多>