我没有用dma,直接调用ADC1_GetVol( 1 , ADC_Channel_9),我的adc用管脚PB1,按理应该是ADC_Channel_9。实际上却在ADC_Channel_0;adc用管脚PA0,按理应该是ADC_Channel_0。实际上却在ADC_Channel_9,怎么会变了? 更郁闷的是程序修改了其它与这个调用ADC1_GetVol无关的地方,原来的adc用ADC_Channel_0,却没有跟随变化了?而adc用管脚PA0,按理应该是ADC_Channel_0。还在ADC_Channel_9。 |
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* DMA1 clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , DISABLE);
/* Configure PA.01 as analog input */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;// ;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStruct);
以前用过很多stm32f103\stm32f107,都没有这个问题。
ADCx->CHSELR = (uint32_t)ADC_Channel; //
不向stm32f103\107
ADC1->SQR3|=ch; //这个是正确的,很容易
请教大侠指点。
单独用一个channel adc是正确的,用3个,作channel切换就不对了?请指点:
/* Convert the selected Channel Vref with 55.5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, ADC_Channel, ADC_SampleTime_239_5Cycles);
// ADC_ChannelConfig(ADC1, ADC_Channel_0 , ADC_SampleTime_55_5Cycles);
// cda_value=2;
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
// ADC_DMACmd(ADC1, DISABLE);
/* Enable ADC1 */
// ADC_Cmd(ADC1, ENABLE);
/* Wait the ADCEN falg */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
if(cda_value==1) RegularConvData_Tab1 = ADC_GetConversionValue(ADC1);
else if(cda_value==2) RegularConvData_Tab2 = ADC_GetConversionValue(ADC1);
else if(cda_value==3) RegularConvData_Tab3 = ADC_GetConversionValue(ADC1);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
/* Wait the ADCEN falg */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
if(ADC_Channel==ADC_Channel_0) RegularConvData_Tab1 = ADC_GetConversionValue(ADC1);
else if(ADC_Channel==ADC_Channel_1) RegularConvData_Tab2 = ADC_GetConversionValue(ADC1);
else if(ADC_Channel==ADC_Channel_9) RegularConvData_Tab3 = ADC_GetConversionValue(ADC1);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
/* Wait the ADCEN falg */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
if(ADC_Channel==ADC_Channel_0) RegularConvData_Tab1 = ADC_GetConversionValue(ADC1);
else if(ADC_Channel==ADC_Channel_1) RegularConvData_Tab2 = ADC_GetConversionValue(ADC1);
else if(ADC_Channel==ADC_Channel_9) RegularConvData_Tab3 = ADC_GetConversionValue(ADC1);