[mw_shl_code=c,true]void ADC_Configuration(void)
{
u32 calibration_value = 0;
u32 Time = 0;
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
// DMA_InitTypeDef DMA_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
/*-------------------------GPIO---------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_SetMode(GPIOC, GPIO_Pin_2 | GPIO_Pin_3, Old_GPIO_Mode_AIN);
/*-------------------------ADC----------------------------*/
/* Configure the ADC clock */
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div12);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
//RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12, ENABLE); //ADC1赂麓脦禄
//RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12, DISABLE); //赂麓脦禄陆谩脢酶
ADC_DeInit(ADC1);
/* Insert delay equal to 10 ? */
ADC_VoltageRegulatorCmd(ADC1, ENABLE);
ResetCounter();
while(GetCounter() < 10);
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Differential);
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1) != RESET);
calibration_value = ADC_GetCalibrationValue(ADC1);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 10;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;
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;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_181Cycles5);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* wait for ADRDY */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
/* Start ADC1 Software Conversion */
ADC_StartConversion(ADC1);
}[/mw_shl_code]
[mw_shl_code=c,true]u16 Get_Adc(u8 Channel)
{
u32 result = 0;
u8 i;
ADC_RegularChannelConfig(ADC1, Channel, 1, ADC_SampleTime_181Cycles5);
ADC_StartConversion(ADC1);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
result = ADC_GetConversionValue(ADC1);
return result;
}[/mw_shl_code]
1. 如果单独使用Get_Adc(ADC_Channel_9);输出值正常;但是如果Get_Adc(ADC_Channel_9);Get_Adc(ADC_Channel_8);这样子调用,两者的返回值跟真实值差异很大,有2V左右的偏差。
2. 在退出WFI模式后,到重新配置HSE前,会导致程序复位。
各大神帮忙看看,感谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>