串口接收的转换值一直再跳,不给adc11通道给电压也一直在跳
void ADC_init()
{
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
ADC_DeInit(ADC1);
delayms(100);
GPIO_Init(GPIOB,GPIO_Pin_7,GPIO_Mode_Out_PP_Low_Fast);
ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_2);
ADC_SamplingTimeConfig(ADC1,ADC_Group_SlowChannels,ADC_SamplingTime_384Cycles);
ADC_Cmd(ADC1,ENABLE);
ADC_ChannelCmd(ADC1,ADC_Channel_11 ,ENABLE);
}
uint16_t ADC_getval()
{
uint16_t ADCdata;
ADC_SoftwareStartConv (ADC1);//开启软件转换
while(!ADC_GetFlagStatus (ADC1,ADC_FLAG_EOC)); //等待转换结束
ADC_ClearFlag (ADC1,ADC_FLAG_EOC); //清除对应标志
ADCdata=ADC_GetConversionValue( ADC1);
return ADCdata;
}
void USART_Init_USR()
{
CLK_PeripheralClockConfig(CLK_Peripheral_USART2,ENABLE);
GPIO_ExternalPullUpConfig(GPIOE, GPIO_Pin_3, ENABLE);
GPIO_ExternalPullUpConfig(GPIOE, GPIO_Pin_4, ENABLE);
USART_Init( USART2, 9600, USART_WordLength_8b, USART_StopBits_1,
USART_Parity_No, USART_Mode_Tx);
USART_Cmd( USART2, ENABLE);
}
void main()
{
uint16_t A;
ADC_init();
USART_Init_USR();
while(1)
{
A=ADC_getval();
USART_SENDL(A);
}
}
串口接收的转换值一直再跳,不给adc11通道给电压也一直在跳
|