Exemplo n.º 1
0
/**
  * @brief ADC初始化
	* @param none
  * @retval none
  * @note  初始化PA.00为ADC1_CH0,单次转换,软件触发ADC转换
  */ 
void ADC_Initialize(void)
{
	ADC_InitTypeDef ADC_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	
	/* 使能GPIOA,ADC1,AFIO时钟 */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1, ENABLE);

	/* 设置ADCCLK分频因子 ADCCLK = PCLK2/6,即 72MHz/6 = 12MHz */
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);

	/* 配置 PA.00 (ADC1_IN0) 作为模拟输入引脚 */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	ADC_DeInit(ADC1);  //将ADC1设为缺省值
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;						//独立模式
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;							//单通道模式
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;						//单次转换
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;		//软件触发ADC转换
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;					//ADC数据右对齐
	ADC_InitStructure.ADC_NbrOfChannel = 1;									//规则转换通道数目
	ADC_Init(ADC1, &ADC_InitStructure);										//根据ADC_InitStruct初始化ADC

	ADC_Cmd(ADC1, ENABLE);	//使能ADC1

	ADC_ResetCalibration(ADC1);	//复位ADC校准寄存器
	while(ADC_GetResetCalibrationStatus(ADC1));	//等待复位校准结束
	ADC_StartCalibration(ADC1);	 //开启AD校准
	while(ADC_GetCalibrationStatus(ADC1));	 //等待校准结束 
}
Exemplo n.º 2
0
/* 函数名:ADC1_Mode_Config*/
static void ADC1_Mode_Config(void)
{
	DMA_InitTypeDef DMA_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;
	
	/* DMA channel1 configuration */
	DMA_DeInit(DMA1_Channel1);
	DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;	 //ADC地址
	DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;//内存地址
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
	DMA_InitStructure.DMA_BufferSize = 4;//开辟4个储存空间
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址固定
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;  //内存地址递增使能
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;	//半字 16位
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;		//循环传输
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;//高优先级
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_Init(DMA1_Channel1, &DMA_InitStructure);
	
	/* Enable DMA channel1 */
	DMA_Cmd(DMA1_Channel1, ENABLE);
	
	/* ADC1 configuration */
	
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	//独立ADC模式
	ADC_InitStructure.ADC_ScanConvMode = ENABLE ; 	 //禁止扫描模式,扫描模式用于多通道采集
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;	//开启连续转换模式,即不停地进行ADC转换
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	//不使用外部触发转换
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 	//采集数据右对齐
	ADC_InitStructure.ADC_NbrOfChannel = 4;	 	//要转换的通道数目1
	ADC_Init(ADC1, &ADC_InitStructure);
	
	/*配置ADC时钟,为PCLK2的8分频,即9Hz*/
	RCC_ADCCLKConfig(RCC_PCLK2_Div8); 
	/*ADCx,通道编号,扫描顺序,采样周期 */ 
	ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);//电池电压
	ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 2, ADC_SampleTime_1Cycles5);//转把
	ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_1Cycles5);//左电机电流
	ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_1Cycles5);//右电机电流
	
	/* Enable ADC1 DMA */
	ADC_DMACmd(ADC1, ENABLE);
	
	/* Enable ADC1 */
	ADC_Cmd(ADC1, ENABLE);
	
	/*复位校准寄存器 */   
	ADC_ResetCalibration(ADC1);
	/*等待校准寄存器复位完成 */
	while(ADC_GetResetCalibrationStatus(ADC1));
	
	/* ADC校准 */
	ADC_StartCalibration(ADC1);
	/* 等待校准完成*/
	while(ADC_GetCalibrationStatus(ADC1));
	
	/* 由于没有采用外部触发,所以使用软件触发ADC转换 */ 
	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 3
0
void adc_init() {
	ADC_InitTypeDef ADC_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);

	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	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_Init(ADC1, &ADC_InitStructure);

	ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_239Cycles5);

	ADC_TempSensorVrefintCmd(ENABLE);

	ADC_Cmd(ADC1, ENABLE);

	ADC_ResetCalibration(ADC1);
	while(ADC_GetResetCalibrationStatus(ADC1));

	ADC_StartCalibration(ADC1);
	while(ADC_GetCalibrationStatus(ADC1));

	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 4
0
static void __ADC_Init(void)
{
	ADC_InitTypeDef ADC_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  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 = (USE_ADC_PB0 + USE_ADC_PB1 + USE_ADC_PA4 + USE_ADC_PC0); //Change
	ADC_Init(ADC1, &ADC_InitStructure);
	#if (USE_ADC_PB0 == 1)
	ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_55Cycles5);
	#endif
	#if (USE_ADC_PB1 == 1)
	ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 2, ADC_SampleTime_55Cycles5);
	#endif
	#if (USE_ADC_PA4 == 1)
	ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3, ADC_SampleTime_55Cycles5);
	#endif
	#if (USE_ADC_PC0 == 1)
	ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 4, ADC_SampleTime_55Cycles5);
	#endif
	ADC_DMACmd(ADC1, ENABLE);
	ADC_Cmd(ADC1, ENABLE);
	ADC_ResetCalibration(ADC1);
	while(ADC_GetResetCalibrationStatus(ADC1));
	ADC_StartCalibration(ADC1);
	while(ADC_GetCalibrationStatus(ADC1));
	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 5
0
/**
 * @brief Initializes the ADC used by the Accelerometer.
 * @retval None
 */
void Accel_ADC_Configuration() {
  ADC_InitTypeDef ADC_InitStructure;

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  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 = 3;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel 10, 11, 12 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_55Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_55Cycles5);

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);
  
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
     
  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 6
0
void fft_ADC_Init(void)
{ 	
	ADC_InitTypeDef ADC_InitStructure; 
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1,ENABLE);	 
 
//	RCC_ADCCLKConfig(RCC_PCLK2_Div6);                                  
	RCC_ADCCLKConfig(RCC_PCLK2_Div8);                                   
	                       
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_1 | GPIO_Pin_2;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;		               
	GPIO_Init(GPIOC, &GPIO_InitStructure);	

	ADC_DeInit(ADC1);                                                

	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	               
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;	                   
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;	               
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;	            
	ADC_InitStructure.ADC_NbrOfChannel = 1;	                          
	ADC_Init(ADC1, &ADC_InitStructure);	                              
 
	ADC_Cmd(ADC1, ENABLE);	                                           
	ADC_ResetCalibration(ADC1);	                                       
	while(ADC_GetResetCalibrationStatus(ADC1));	                        
	ADC_StartCalibration(ADC1);		                                 
	while(ADC_GetCalibrationStatus(ADC1));		                        
	ADC_SoftwareStartConvCmd(ADC1, ENABLE);		                       
}				  
Exemplo n.º 7
0
/*
      Function £º
			  Initialize ADC function 
	    Parameters£º

	    Return values£º

*/
static my_random_ADC_Init(void)
{
 	ADC_InitTypeDef ADC_InitStructure;
 
    //The following are ADC1's registers settings 
  	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//AD module will select as independent mode 
  	ADC_InitStructure.ADC_ScanConvMode = ENABLE;//auto scan mode has been enable 
  	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//Continuous convertion mode is enable 
  	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//Not external trigger interrupt function  
  	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//data align to right 
  	ADC_InitStructure.ADC_NbrOfChannel = 1;//initialize ADC channel into 1 
  	ADC_Init(ADC1, &ADC_InitStructure);//Build ADC1 settings 
  	//PA0 & ADC1 related channel is 0
  	ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5);
	  //USE ADC1
  	ADC_Cmd(ADC1, ENABLE);
  	//Reset ADC1's regiters  
  	ADC_ResetCalibration(ADC1);
    //Wait until the reset has been done  	
  	while(ADC_GetResetCalibrationStatus(ADC1));
  	//Start the calibration for ADC1 
  	ADC_StartCalibration(ADC1);
  	//Wait until ADC1 calibration has been done  	
  	while(ADC_GetCalibrationStatus(ADC1));
    //Convert to use ADC1 
  	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 8
0
void InitADC(void) {
	ADC_InitTypeDef adc;

	RCC_ADCCLKConfig(RCC_PCLK2_Div6);

	adc.ADC_Mode = ADC_Mode_Independent;
	adc.ADC_NbrOfChannel = 1;
	adc.ADC_ScanConvMode = DISABLE;
	adc.ADC_DataAlign = ADC_DataAlign_Right;
	adc.ADC_ContinuousConvMode = ENABLE;
	adc.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_Init(AN_ADCx, &adc);

	ADC_RegularChannelConfig(AN_ADCx, AN_CHx, 1, ADC_SampleTime_7Cycles5);
	ADC_Cmd(AN_ADCx, ENABLE);

	ADC_ResetCalibration(AN_ADCx);

	while (ADC_GetResetCalibrationStatus(AN_ADCx)) {};
	ADC_StartCalibration(AN_ADCx);

	while (ADC_GetCalibrationStatus(AN_ADCx));
	ADC_SoftwareStartConvCmd(AN_ADCx,ENABLE);


}
Exemplo n.º 9
0
// --------------------------------------------------------------------------
void adcInit(const UINT8 ui8_reference, const UINT8 ui8_prescaler)
{
	ADC_InitTypeDef adc;

	// suppress compiler complaints
	(void)ui8_reference;

	// configure ADC clock (must not exceed 14MHz)
	RCC_ADCCLKConfig(prescaler_reg[ui8_prescaler]);
	RCC_APB2PeriphClockCmd(ADC_RCC, ENABLE);

	// reset current settings
	ADC_DeInit(ADC_PERIPH);
	
	ADC_StructInit(&adc);
	adc.ADC_Mode = ADC_Mode_Independent;
	adc.ADC_ScanConvMode = DISABLE;
	adc.ADC_ContinuousConvMode = DISABLE;
	adc.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	adc.ADC_DataAlign = ADC_DataAlign_Right;
	adc.ADC_NbrOfChannel = 1;
	ADC_Init(ADC_PERIPH, &adc);
	ADC_Cmd(ADC_PERIPH, ENABLE);

	// perform calibration, not needed but it don't hurt
	ADC_ResetCalibration(ADC_PERIPH);
  	WAIT_FOR(ADC_GetResetCalibrationStatus(ADC_PERIPH));
	ADC_StartCalibration(ADC_PERIPH);
	WAIT_FOR(ADC_GetCalibrationStatus(ADC_PERIPH));
}
Exemplo n.º 10
0
/*******************************************************************************
* Function Name  : USART1_IRQHandler
* Description    : This function handles USART1 global interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void USART1_IRQHandler(void)
{	

	USART_ClearITPendingBit(USART1, USART_IT_RXNE);
	
   if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
   {
	   	Rx_Buffer[data]=USART_ReceiveData(USART1);
			
		Usart_Putnum(Rx_Buffer[data]);

		if(Rx_Buffer[data]==1){
			/* Enable ADC1 DMA */
		    ADC_DMACmd(ADC1, ENABLE);

		    /* Enable ADC1 */
		    ADC_Cmd(ADC1, ENABLE);

		    /* Enable ADC1 reset calibaration register */   
		    ADC_ResetCalibration(ADC1);
		    /* Check the end of ADC1 reset calibration register */
		    while(ADC_GetResetCalibrationStatus(ADC1));

		    /* Start ADC1 calibaration */
		    ADC_StartCalibration(ADC1);
		    /* Check the end of ADC1 calibration */
		    while(ADC_GetCalibrationStatus(ADC1));
		 
		    /* Start ADC1 Software Conversion */ 
		    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
		}

		else if(Rx_Buffer[data]==2)
			 ADC_Cmd(ADC1, DISABLE);
		else if(Rx_Buffer[data]==3)
		Usart_Putnum(TIM_GetCounter(TIM4));
		
	
   }

   
	//{	
		//Rx_Buffer[data]=data;
		//data++;
		//USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		/*Rx_Buffer[data]=USART_ReceiveData(USART1);
		
		Usart_Putnum(Rx_Buffer[data]);
		data++;*/
		/*
		if(Rx_Buffer[data]==1)
		Usart_Putnum(10);
		else if(Rx_Buffer[data]==2)
		Usart_Putnum(20);
		*/
	
    
	
	
}
Exemplo n.º 11
0
void ADC_Configuration(void)
{
  ADC_InitTypeDef  ADC_InitStructure;
  RCC_ADCCLKConfig(RCC_PCLK2_Div6);                                    // PCLK2 is the APB2 clock, ADCCLK = PCLK2/6 = 60/6 = 10MHz
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);                 // Enable ADC1 clock so that we can talk to it
  ADC_DeInit(ADC1);                                                    // Put everything back to power-on defaults

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;                   // ADC2 not depenedent on ADC1
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;                        // Disable the scan conversion so we do one at a time
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;                  // Don't do contimuous conversions - do them on demand
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;  // Start conversin by software, not an external trigger
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;               // Conversions are 12 bit - put them in the lower 12 bits of the result
  ADC_InitStructure.ADC_NbrOfChannel = 1;                              // How many channels would be used by the sequencer
  ADC_Init(ADC1, &ADC_InitStructure);
  ADC_Cmd(ADC1, ENABLE);

  ADC_ResetCalibration(ADC1);                                           // Enable ADC1 reset calibaration register
  while(ADC_GetResetCalibrationStatus(ADC1));                           // Check the end of ADC1 reset calibration register
  ADC_StartCalibration(ADC1);                                           // Start ADC1 calibaration
  while(ADC_GetCalibrationStatus(ADC1));                                // Check the end of ADC1 calibration
  ADC_TempSensorVrefintCmd(ENABLE);                                     // enable Vrefint and Temperature sensor

  GPIO_InitTypeDef  GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;                           // Pin #0
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AIN;                        // as analog input
  GPIO_Init(GPIOB, &GPIO_InitStructure);                                // for Port B

}
Exemplo n.º 12
0
void sensor_init(void)
{
    // 0. Run clocks
    RCC_AHBPeriphClockCmd(SENSORS_DMA_RCC, ENABLE);
    RCC_APB2PeriphClockCmd(SENSORS_ADC_RCC, ENABLE);

    // 1. Init ADC
    ADC_Init(SENSORS_ADC, &_adc);

    // 2. Init DMA for writing measures directly to array
    DMA_Init(SENSORS_DMA, &_dma); // SENSORS_ADC is on DMA1 channel 1

    // 3. Setup SENSORS_ADC to send DMA requests
    ADC_DMACmd(SENSORS_ADC, ENABLE);

    // 4. Enable DMA
    DMA_Cmd(SENSORS_DMA, ENABLE);

    // 5. Enable ADC
    ADC_Cmd(SENSORS_ADC, ENABLE);

    // 6. Calibrate ADC
    ADC_ResetCalibration(SENSORS_ADC);
    while(ADC_GetResetCalibrationStatus(SENSORS_ADC));;;

    ADC_StartCalibration(SENSORS_ADC);
    while(ADC_GetCalibrationStatus(SENSORS_ADC));;;
}
Exemplo n.º 13
0
void TEMP_Init()			//单次,单通道
{
	ADC_InitTypeDef ADC_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1,ENABLE);
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);			//ADC时钟 = 72M/6 = 12M;
	
	
	//ADC_初始化
	ADC_DeInit(ADC1);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfChannel = 1;
	ADC_Init(ADC1,&ADC_InitStructure);

	ADC_TempSensorVrefintCmd(ENABLE);	//使能内部温度传感器(或参考电压)//======
	ADC_Cmd(ADC1,ENABLE);

	//校准
	ADC_ResetCalibration(ADC1);
	while(ADC_GetResetCalibrationStatus(ADC1));
	ADC_StartCalibration(ADC1);
	while(ADC_GetCalibrationStatus(ADC1));
}
Exemplo n.º 14
0
int main(void) {
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef TIM_InitStructure;
  ADC_InitTypeDef ADC_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  TIM_TimeBaseStructInit(&TIM_InitStructure);
  TIM_InitStructure.TIM_Prescaler = 10000;
  TIM_InitStructure.TIM_Period = 100;
  TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM3, &TIM_InitStructure);

  TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_55Cycles5);
  ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);

  NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  ADC_Cmd(ADC1, ENABLE);

  while(ADC_GetResetCalibrationStatus(ADC1));
  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));

  TIM_Cmd(TIM3, ENABLE);

  if (SysTick_Config(SystemCoreClock / 1000))
    while (1);

  while(1);
}
Exemplo n.º 15
0
Arquivo: adc.c Projeto: vcheung/STM32
/* 函数名:ADC1_Mode_Config
 * 描述  :配置ADC1的工作模式为MDA模式
 *
 *             使用 DMA1 的通道 1,数据从 ADC 外设的数据寄存器(ADC1_DR_Address)
 *         转移到内存(ADC_ConvertedValue 变量),内存、外设地址都固定,每次传输的
 *         数据大小为半字(16 位),使用 DMA 循环传输模式。
 *
 * 输入  : 无
 * 输出  :无
 * 调用  :内部调用
 */
static void ADC1_Mode_Config(void)
{
	DMA_InitTypeDef DMA_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;
	
	/* DMA channel1 configuration */
	DMA_DeInit(DMA1_Channel1);

	/* ADC_DR 数据寄存器保存了 ADC 转换后的数值,以它作为 DMA 的传输源地址 */
	DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;	 //ADC1_DR规则寄存器的地址,查RM0008 STM32F10x参考手册

	DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;//ADC_ConvertedValue的内存地址
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
	DMA_InitStructure.DMA_BufferSize = 1;
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址固定
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;  //内存地址固定
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;	//半字
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;		//循环传输
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_Init(DMA1_Channel1, &DMA_InitStructure);
	
	/* Enable DMA channel1 */
	DMA_Cmd(DMA1_Channel1, ENABLE);
	
	/* ADC1 configuration */	
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	//独立ADC模式
	ADC_InitStructure.ADC_ScanConvMode = DISABLE ; 	 //禁止扫描模式,扫描模式用于多通道采集
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;	//开启连续转换模式,即不停地进行ADC转换
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	//不使用外部触发转换
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 	//采集数据右对齐
	ADC_InitStructure.ADC_NbrOfChannel = 1;	 	//要转换的通道数目1
	ADC_Init(ADC1, &ADC_InitStructure);
	
	/*配置ADC时钟,为PCLK2的8分频,即9Hz*/
	RCC_ADCCLKConfig(RCC_PCLK2_Div8); 
	/*配置ADC1的通道7为55.	5个采样周期,序列为1 */ 
	ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_55Cycles5);
	
	/* Enable ADC1 DMA */
	ADC_DMACmd(ADC1, ENABLE);
	
	/* Enable ADC1 */
	ADC_Cmd(ADC1, ENABLE);
	
	/*复位校准寄存器 */   
	ADC_ResetCalibration(ADC1);
	/*等待校准寄存器复位完成 */
	while(ADC_GetResetCalibrationStatus(ADC1));
	
	/* ADC校准 */
	ADC_StartCalibration(ADC1);
	/* 等待校准完成*/
	while(ADC_GetCalibrationStatus(ADC1));
	
	/* 由于没有采用外部触发,所以使用软件触发ADC转换 */ 
	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 16
0
Arquivo: adc.c Projeto: kenziD/ANO
static void ADC1_Mode_Config(void)
{
	DMA_InitTypeDef DMA_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;
	/* DMA channel1 configuration */
	DMA_DeInit(DMA1_Channel1);
//	DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;	 			//ADC地址
 DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&ADC1->DR;
	DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;	//貌似要把地址符号去掉
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
	DMA_InitStructure.DMA_BufferSize = 40;                             //缓冲区的大小也要修改
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;	//外设地址固定
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;  				//内存地址固定这个要修改!
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;	//半字
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;										          //循环传输
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_Init(DMA1_Channel1, &DMA_InitStructure);
	/* Enable DMA channel1 */
	DMA_Cmd(DMA1_Channel1, ENABLE);
	
	
	/* ADC1 configuration */	
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;			//独立ADC模式
	ADC_InitStructure.ADC_ScanConvMode = ENABLE ; 	 				//修改:开启扫描模式,用于多通道扫描 
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;			//开启连续转换模式,即不停地进行ADC转换
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	//不使用外部触发转换
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 	//采集数据右对齐
	ADC_InitStructure.ADC_NbrOfChannel = 4;	 								//要转换的通道数目4
	ADC_Init(ADC1, &ADC_InitStructure);


	/*配置ADC时钟,为PCLK2的8分频,即9MHz*/
	RCC_ADCCLKConfig(RCC_PCLK2_Div8); 
	/*配置ADC1的通道1为55.	5个采样周期,序列为1 */ 
	ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_55Cycles5);
	ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_55Cycles5);
	ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 3, ADC_SampleTime_55Cycles5);
	ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 4, ADC_SampleTime_55Cycles5);
	/* Enable ADC1 DMA */
	ADC_DMACmd(ADC1, ENABLE);
	
	/* Enable ADC1 */
	ADC_Cmd(ADC1, ENABLE);
	
	/*复位校准寄存器 */   
	ADC_ResetCalibration(ADC1);
	/*等待校准寄存器复位完成 */
	while(ADC_GetResetCalibrationStatus(ADC1));
	
	/* ADC校准 */
	ADC_StartCalibration(ADC1);
	/* 等待校准完成*/
	while(ADC_GetCalibrationStatus(ADC1));
	
	/* 由于没有采用外部触发,所以使用软件触发ADC转换 */ 
	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 17
0
void adc_init (void)
{
  /* ADCCLK = PCLK2/8 */
  RCC_ADCCLKConfig(RCC_PCLK2_Div8);

  /* Enable DMA1 clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  DMA_InitTypeDef DMA_InitStructure;
  /* DMA1 channel1 configuration ----------------------------------------------*/
  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &(ADC1->DR);
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &adc_value;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = 1;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);

  /* Enable DMA1 channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);

  ADC_InitTypeDef ADC_InitStructure;
  /* ADC1 configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  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 = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel0 configuration */
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5);

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibration register */
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));

  /* Start ADC1 Software Conversion */
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 18
0
static void ADC1_Mode_Config(void)
{
	DMA_InitTypeDef DMA_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;

	/* DMA channel1 configuration */
  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;    //DMA外设基地址
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;  //DMA内存基地址
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;      //数据传输方向,从外设发送到内存
  DMA_InitStructure.DMA_BufferSize = 1;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;   //外设地址寄存器不变
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;            //内存地址寄存器递增
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;   //工作在循环缓存模式
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  
  /* Enable DMA channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);
     
  /* ADC1 configuration */
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	//独立模式 每个ADC独立工作
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;				 //使用扫描模式  scan位设置
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;	// cont位设置 连续转换模式
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	;//EXTSEL 选择启动规则通道组转换的外部事件 设置成有软件控制
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;	//数据对齐 由软件置位和清楚   这里设置成右对齐
  ADC_InitStructure.ADC_NbrOfChannel = 1;		//规则通道序列长度 这些位由软件定义在规则通道转换序列中的通道数目 1个转换 指定由多少个通道被转换
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel11 configuration */ 
	ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_55Cycles5);	//转换时间是55.5个周期


  /* Enable ADC1 external trigger */
  ADC_ExternalTrigConvCmd(ADC1, DISABLE);

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);
  
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
     
  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 19
0
/*****************************************************************************
** 函数名称: HexToASCII
** 功能描述: 将数值转化成字符
				0x30 代表字符0 比如1234 转化为 ”1234“
** 作   者: Dream
** 日   期: 2010年12月06日
*****************************************************************************/
void Temp_Init()
{
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // 使能 MDA 重要!!!
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);// 使能 ADC1 重要!!!

  /* DMA1 channel1 configuration ----------------------------------------------*/
  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = 1;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  
  /* Enable DMA1 channel 1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);
     
  /* ADC1 configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  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 = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel 14 configuration */ 
  /* 内部温度传感器 Channel 16 */
  ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_55Cycles5);

  /* Enable the temperature sensor and vref internal channel */
  ADC_TempSensorVrefintCmd(ENABLE);	    //内部温度传感器  添加这一句 

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);
  
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   //使用之前一定要校准
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
     
  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 20
0
/*配置ADC1的工作模式为MDA模式  */
 void ADC1_Mode_Config(void)
{
  DMA_InitTypeDef DMA_InitStructure;
  ADC_InitTypeDef ADC_InitStructure;	
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //使能DMA1时钟
	/* DMA channel1 configuration */
  DMA_DeInit(DMA1_Channel1);  //指定DMA通道
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//设置DMA外设地址
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;	//设置DMA内存地址,ADC转换结果直接放入该地址
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //外设为设置为数据传输的来源
  DMA_InitStructure.DMA_BufferSize = 1;	//DMA缓冲区设置为1;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  
  /* Enable DMA channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);  //使能DMA通道

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);	//使能ADC1时钟
     
  /* ADC1 configuration */
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //使用独立模式,扫描模式
  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 = 1;  // 只有1个转换通道
  ADC_Init(ADC1, &ADC_InitStructure);
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);   //72M/6=12,ADC最大时间不能超过14M	

  /* ADC1 regular channel11 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5); //通道1采样周期55.5个时钟周期

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);	 //使能ADC的DMA
  
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE); //使能ADC1

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
     
  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);  //开始转换
}
Exemplo n.º 21
0
/*******************************************************************************
* Description : ADC_setup
* Syntax      : 
* Parameters I: 
* Parameters O: 
* return      : 
*******************************************************************************/
void ADC1_setup(void)
{
    /* Check the parameters */
//    ASSERT ();
    
    /* Resets ADC1 */
    ADC_DeInit(ADC1);
    
    /* 41 pin(PC1) 配置为模拟输入,输入时不用设置速率 */
    pinMode(A41, INPUT_ANALOG);
    
    ADC_InitTypeDef ADC_InitStructure;

    /*** ADC1 configuration ***/
    /* Enable ADC1 clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    
    /* 独立 ADC 模式 */
    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
    /* 禁止扫描模式,扫描模式用于多通道采集 */
    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
    /* 开启连续转换模式,即不停地进行 ADC 转换 */
    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
    /* 不使用外部触发转换 */
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
    /* 采集数据右对齐  0000 D11 - D0 */
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    /* 要转换的通道数目 1*/
    ADC_InitStructure.ADC_NbrOfChannel = 1;

    ADC_Init(ADC1, &ADC_InitStructure);

    /*配置 ADC 时钟,为 PCLK2 的 8 分频,即 9Hz*/
    RCC_ADCCLKConfig(RCC_PCLK2_Div8);
    /*配置 ADC1 的通道 11 为 55.5 个采样周期 */
    ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5);
    //...
    
    /* Enable ADC1 DMA */
    ADC_DMACmd(ADC1, ENABLE);
    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);
    
    /*复位校准寄存器 */
    ADC_ResetCalibration(ADC1);
    
    /*等待校准寄存器复位完成 */
    while(ADC_GetResetCalibrationStatus(ADC1));

    /* ADC 校准 */
    ADC_StartCalibration(ADC1);
    /* 等待校准完成*/
    while(ADC_GetCalibrationStatus(ADC1));

    /* 使用软件触发 ADC 转换 */
    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 22
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();

  /* NVIC configuration ------------------------------------------------------*/
  NVIC_Configuration();

  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();

  /* Configure LED GPIO Pin ------------------------------------------------- */
  STM_EVAL_LEDInit(LED1);

  /* ADC1 Configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  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_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel14 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);

  /* Configure high and low analog watchdog thresholds */
  ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0B00, 0x0300);
  /* Configure channel14 as the single analog watchdog guarded channel */
  ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_14);
  /* Enable analog watchdog on one regular channel */
  ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);

  /* Enable AWD interupt */
  ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));

  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  while (1)
  {
  }
}
Exemplo n.º 23
0
/*****************************************************************************
** 函数名称: adc_Init
** 功能描述: ADC初始化
** 作   者: Dream
** 日   期: 2010年12月06日
*****************************************************************************/
void adc_Init()
{
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // 使能 MDA 重要!!!
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);// 使能 ADC1 重要!!!

	/*DMA1 channel1 configuration ----------------------------------------------*/
  	DMA_DeInit(DMA1_Channel1);			   //将DMA的通道1寄存器重设为缺省值
  	DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;	  //定义DMA外设基地址为ADC1
  	DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; //定义DMA内存基地址
  	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;	  //外设作为数据传输的来源
  	DMA_InitStructure.DMA_BufferSize = 1;	  //定义指定DMA通道的DMA缓存的大小
  	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  //外设地址寄存器不变
  	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;		//内存地址寄存器不变
  	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;	//数据宽度为16位
  	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;	//数据宽度为16位
  	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;	  //工作在循环缓存模式
  	DMA_InitStructure.DMA_Priority = DMA_Priority_High;	//DMA通道1拥有高优先级
  	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;	//DMA通道1没有设置为内存到内存传输
  	DMA_Init(DMA1_Channel1, &DMA_InitStructure);	 
  
  	/* Enable DMA1 channel1 */
  	DMA_Cmd(DMA1_Channel1, ENABLE);			 
     
  	/* ADC1 configuration ------------------------------------------------------*/
  	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	 //独立工作模式
  	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 = 1;
  	ADC_Init(ADC1, &ADC_InitStructure);

  	/* ADC1 regular channel_8,configuration */ 
  	ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_55Cycles5); //转换时间为17.1US

  	/* Enable ADC1 DMA */
  	ADC_DMACmd(ADC1, ENABLE);
  
  	/* Enable ADC1 */
  	ADC_Cmd(ADC1, ENABLE);

  	/* Enable ADC1 reset calibaration register */   
  	ADC_ResetCalibration(ADC1);

  	/* Check the end of ADC1 reset calibration register */
  	while(ADC_GetResetCalibrationStatus(ADC1));

  	/* Start ADC1 calibaration */
  	ADC_StartCalibration(ADC1);

  	/* Check the end of ADC1 calibration */
  	while(ADC_GetCalibrationStatus(ADC1));
     
  	/* Start ADC1 Software Conversion */ 
  	ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 24
0
static void ADC_Enable(ADC_TypeDef* ADCx)
{
	ADC_Cmd(ADCx, ENABLE);

	/* do calibration */
	ADC_ResetCalibration(ADCx);
	while(ADC_GetResetCalibrationStatus(ADCx));
	ADC_StartCalibration(ADCx);
	while(ADC_GetCalibrationStatus(ADCx));
}
Exemplo n.º 25
0
 void ADC1_MODE_Config(void)
{

  DMA_InitTypeDef DMA_InitStructure;					//定义一个DMA结构体变量
  ADC_InitTypeDef ADC_InitStructure;					//定义一个ADC结构体变量

  DMA_DeInit(DMA1_Channel1);		  //开启DMA1的第一通道
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)&ADC_ConvertedValue;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;	//DMA的转换模式为SRC模式,由外设搬移到内存
  DMA_InitStructure.DMA_BufferSize = 1; //DMA缓存大小,1个
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;	//接收一次数据后,设备地址禁止后移
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;	//关闭接收一次数据后,目标内存地址后移
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  //定义外设数据宽度为16位
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;  //DMA搬移数据尺寸,HalfWord就是为16位
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;   //转换模式,循环缓存模式。
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;	//DMA优先级高
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;		  //M2M模式禁用
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);          
  /* Enable DMA1 channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);

  ADC_TempSensorVrefintCmd(ENABLE);

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;		//独立的转换模式
  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 = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel14 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_239Cycles5);

  /* Enable ADC1 DMA */
  ADC_DMACmd(ADC1, ENABLE);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
     
  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

}
Exemplo n.º 26
0
/*=====================================================================================================*/
void ADC_Config( void )
{
  DMA_InitTypeDef DMA_InitStruct;
  ADC_InitTypeDef ADC_InitStruct;
  GPIO_InitTypeDef GPIO_InitStruct;

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA, ENABLE);

  /* ADC_1 PA4 */	/* ADC_2 PA5 */	/* ADC_3 PA6 */	/* ADC_4 PA7 */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* ADC DMA Init *************************************************************/
  DMA_DeInit(DMA1_Channel1);
  DMA_InitStruct.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS;                    // Peripheral address
  DMA_InitStruct.DMA_MemoryBaseAddr = (u32)&ADC_DMA_Buf;                      // DMA內存地址
  DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;                             // 內存作為數據傳輸的目的地
  DMA_InitStruct.DMA_BufferSize = ADC_Sample*ADC_Channel;                     // DMA通道的DMA緩存的大小
  DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;               // 外設地址寄存器不變
  DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;                        // 內存地址寄存器遞增
  DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;    // 數據寬度為16位
  DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;            // 數據寬度為16位
  DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;                                // 循環模式開啟,Buffer寫滿後,自動回到初始地址開始傳輸
  DMA_InitStruct.DMA_Priority = DMA_Priority_High;                            // DMA通道x擁有高優先級
  DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;                                   // DMA通道x沒有設置為內存到內存傳輸
  DMA_Init(DMA1_Channel1, &DMA_InitStruct);
  DMA_Cmd(DMA1_Channel1, ENABLE);

  /* ADC Init *****************************************************************/
  ADC_InitStruct.ADC_Mode = ADC_Mode_Independent;                             // ADC1 和 ADC2 工作在獨立模式 
  ADC_InitStruct.ADC_ScanConvMode = ENABLE;                                   // 掃描模式 
  ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;                             // 連續轉換模式 
  ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;            // 外部觸發關閉
  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;                         // ADC數據右對齊
  ADC_InitStruct.ADC_NbrOfChannel = ADC_Channel;                              // 轉換ADC通道數目
  ADC_Init(ADC1, &ADC_InitStruct);

  /* ADC Regular Config *******************************************************/
  // 設置指定ADC的規則組通道,設置它們的轉化順序和采樣時間
  // ADC1, ADC通道x, 規則采樣順序值為y, 采樣時間為239.5週期
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_55Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_55Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 3, ADC_SampleTime_55Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 4, ADC_SampleTime_55Cycles5);

  ADC_DMACmd(ADC1, ENABLE);
  ADC_Cmd(ADC1, ENABLE);
  ADC_ResetCalibration(ADC1);
  while(ADC_GetResetCalibrationStatus(ADC1));
  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
Exemplo n.º 27
0
void ADC_Prepare()
{
	ADC_Cmd(ADC1, ENABLE);//使能ADC1
	
	ADC_ResetCalibration(ADC1); //重置ADC1校准寄存器
	while(ADC_GetResetCalibrationStatus(ADC1));//等待ADC1校准重置完成
	ADC_StartCalibration(ADC1);//开始ADC1校准
	while(ADC_GetCalibrationStatus(ADC1));//等待ADC1校准完成
	
	ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能ADC1软件开始转换
}
Exemplo n.º 28
0
void halInternalInitAdc(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  ADC_InitTypeDef ADC_InitStructure;
  
  //Configure TEMP_ENABLE GPIO as push-pull output, defaulting to active/on
  GPIO_WriteBit(TEMP_ENABLE_PORT, TEMP_ENABLE_PIN, Bit_SET);
  GPIO_InitStructure.GPIO_Pin = TEMP_ENABLE_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(TEMP_ENABLE_PORT, &GPIO_InitStructure);
  
  //Configure TEMP_SENSE GPIO as analog input
  GPIO_InitStructure.GPIO_Pin = TEMP_SENSOR_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(TEMP_SENSOR_PORT, &GPIO_InitStructure);
  
  //Divide down the APB2 clock (72MHz) to get an ADC clock of 12MHz (<= 14MHz)
  RCC_ADCCLKConfig(RCC_PCLK2_Div6);
  
  //Configure ADC to be in independent, single conversion mode
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(TEMP_SENSOR_ADC, &ADC_InitStructure);
  
  //Configure sample times to longest (recommended for temp measure)
  ADC_RegularChannelConfig(TEMP_SENSOR_ADC,
                           TEMP_SENSOR_ADC_CHAN,
                           1,
                           ADC_SampleTime_239Cycles5);
  
  //Enable ADC
  ADC_Cmd(TEMP_SENSOR_ADC, ENABLE);
  
  //Reset ADC calibration registers
  ADC_ResetCalibration(TEMP_SENSOR_ADC);
  
  //Wait for cal reset to complete
  while(ADC_GetResetCalibrationStatus(TEMP_SENSOR_ADC) == SET) {}
  
  //Calibrate the ADC
  ADC_StartCalibration(TEMP_SENSOR_ADC);
  
  //Wait for cal to complete
  while(ADC_GetCalibrationStatus(TEMP_SENSOR_ADC) == SET) {}
  
  //This driver does not use interrupts; it's purely polling.
}
Exemplo n.º 29
0
void ADCManager_Structure(ADCManagerTypeDef *ADCManager)
{

	ADC_InitTypeDef ADC_InitStructure; 
	GPIO_InitTypeDef GPIO_InitStructure;
	u8 i;
	defaultADCManager=ADCManager;
	defaultADCManager->getData=ADCManager_getData;
	defaultADCManager->startTransfer=ADCManager_startTransfer;
	//defaultADCManager->ADC_Channels_num=sizeof(defaultADCManager->ADC_Channels);
	RCC_APB2PeriphClockCmd(filterGPIO_RCC_ADC() | RCC_APB2Periph_ADC1	, ENABLE );	  //使能ADC1通道时钟
 
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);   //设置ADC分频因子6 72M/6=12,ADC最大时间不能超过14M

	for(i=0;i<defaultADCManager->ADC_Channels_num;i++)
	{
		if(defaultADCManager->ADC_Channels[i]==ADC_Channel_16|defaultADCManager->ADC_Channels[i]==ADC_Channel_17)
			continue;
		GPIO_InitStructure.GPIO_Pin = filterPin_ADC(defaultADCManager->ADC_Channels[i]);
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;		//模拟输入引脚
		GPIO_Init(filterGPIO_ADC(defaultADCManager->ADC_Channels[i]), &GPIO_InitStructure);	
	}                    

	ADC_DeInit(ADC1);  //复位ADC1,将外设 ADC1 的全部寄存器重设为缺省值

	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;	//ADC工作模式:ADC1和ADC2工作在独立模式
	ADC_InitStructure.ADC_ScanConvMode = ENABLE;	//模数转换工作在单通道模式
	ADC_InitStructure.ADC_ContinuousConvMode = (FunctionalState)defaultADCManager->isContinus;	//模数转换工作在单次转换模式
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;	//转换由软件而不是外部触发启动
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;	//ADC数据右对齐
	ADC_InitStructure.ADC_NbrOfChannel = defaultADCManager->ADC_Channels_num;	//顺序进行规则转换的ADC通道的数目
	ADC_Init(ADC1, &ADC_InitStructure);	//根据ADC_InitStruct中指定的参数初始化外设ADCx的寄存器   

	for(i=0;i<defaultADCManager->ADC_Channels_num;i++)
	{
		if(defaultADCManager->ADC_Channels[i]==ADC_Channel_16|defaultADCManager->ADC_Channels[i]==ADC_Channel_17)
			ADC_TempSensorVrefintCmd(ENABLE);
		ADC_RegularChannelConfig(ADC1, defaultADCManager->ADC_Channels[i], i+1, ADC_SampleTime_239Cycles5 );	//ADC1,ADC通道,采样时间为239.5周期	
	}
	
	ADC_DMA_Config();
	ADC_DMACmd(ADC1, ENABLE); 
	
	ADC_Cmd(ADC1, ENABLE);	//使能指定的ADC1
	
	ADC_ResetCalibration(ADC1);	//使能复位校准  
	 
	while(ADC_GetResetCalibrationStatus(ADC1));	//等待复位校准结束
	
	ADC_StartCalibration(ADC1);	 //开启AD校准
 
	while(ADC_GetCalibrationStatus(ADC1));	 //等待校准结束
}
Exemplo n.º 30
0
void  adc_init( void )
{
  ADC_InitTypeDef               ADC_InitStructure;
  GPIO_InitTypeDef              GPIO_InitStructure;
  
  // enable DMA1 clock
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1, ENABLE );
  
  // enable ADC1 clock
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1, ENABLE );
  
  GPIO_InitStructure.GPIO_Pin   = (uint16)(ADC_PIN_INT_BATT |
                                           ADC_PIN_EXT_BATT | ADC_PIN_PT100);
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AIN;
  GPIO_Init( GPIOC, &GPIO_InitStructure );
	
	adc_dma_config();
	
  ADC_InitStructure.ADC_Mode                = ADC_Mode_Independent;
  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        = 1;
//  ADC_InitStructure.ADC_NbrOfChannel        = ADC_IX_MAX;
  ADC_Init( ADC1, &ADC_InitStructure );

  /* ADC1 RegularChannelConfig */ 
//  ADC_RegularChannelConfig( ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5 );
  ADC_RegularChannelConfig( ADC1, ADC_Channel_11, 1, ADC_SampleTime_13Cycles5 );
//  ADC_RegularChannelConfig( ADC1, ADC_Channel_12, 3, ADC_SampleTime_13Cycles5 );

  /* Enable ADC DMA interface */
  ADC_DMACmd( ADC1, ENABLE );
  
  /* Enable ADC1 */
  ADC_Cmd( ADC1, ENABLE );
  
  /* Enable ADC1 reset calibration register */
  ADC_ResetCalibration( ADC1 );
  /* Check the end of ADC1 reset calibration register */
  while( ADC_GetResetCalibrationStatus( ADC1 ) );
  
  /* Start ADC1 calibration */
  ADC_StartCalibration( ADC1 );
  /* Check the end of ADC1 calibration */
  while( ADC_GetCalibrationStatus( ADC1 ) );
  
  /* Start ADC1 conversion */ 
  ADC_SoftwareStartConvCmd( ADC1, ENABLE );

}   // end of adc_init()