码迷,mamicode.com
首页 > 其他好文 > 详细

STM32F0库函数初始化系列:ADC

时间:2019-07-29 17:45:37      阅读:704      评论:0      收藏:0      [点我收藏+]

标签:let   tco   scan   reg   函数   flags   conf   value   art   

static void ADC_Config(void)
{
  ADC_InitTypeDef     ADC_InitStructure;

  
  /* ADCs DeInit */  
  //ADC_DeInit(ADC1);
  
  /* Initialize ADC structure */
  ADC_StructInit(&ADC_InitStructure);
  
  /* Configure the ADC1 in continuous mode with a resolution equal to 12 bits  */
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; 
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
  ADC_Init(ADC1, &ADC_InitStructure); 
  
  /* Convert the ADC1 Channel 9 with 239.5 Cycles as sampling time */  
  ADC_ChannelConfig(ADC1, ADC_Channel_9 , ADC_SampleTime_239_5Cycles);
  /* ADC Calibration */
  ADC_GetCalibrationFactor(ADC1);
  
  /* ADC DMA request in circular mode */
  //ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
  
  /* Enable ADC_DMA */
  //ADC_DMACmd(ADC1, ENABLE);  
  
  /* Enable the ADC peripheral */
  ADC_Cmd(ADC1, ENABLE);     
  
  /* Wait the ADRDY flag */
  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)); 
  
  /* ADC1 regular Software Start Conv */ 
  ADC_StartOfConversion(ADC1);
  
}

 while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//等待转换结束
      _adc=ADC_GetConversionValue(ADC1);

 

STM32F0库函数初始化系列:ADC

标签:let   tco   scan   reg   函数   flags   conf   value   art   

原文地址:https://www.cnblogs.com/penuel/p/11265193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!