STM32F103:ADC采样——定时器触发+DMA传输

实现ADC多通道采样,采用DMA传输,采样由定时器触发

初始化代码:

void  Adc_Init(void)
{ 		
	GPIO_InitTypeDef GPIO_InitStructure;
	DMA_InitTypeDef DMA_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;	
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_ADC1, ENABLE );
	
	// IO口
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//ADC0
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;//ADC1
	GPIO_Init(GPIOA, &GPIO_InitStructure);	
	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//ADC2
	GPIO_Init(GPIOA, &GPIO_InitStructure);	
	
	// IO口
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//ADC3
	GPIO_Init(GPI

你可能感兴趣的:(stm32,单片机,stm32,c语言)