这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » stm32 ADC DMA

共1条 1/1 1 跳转至

stm32 ADC DMA

工程师
2014-09-28 19:30:55     打赏
//定义寄存器地址
#define ADC1_DR_Address    ((u32)0x4001244C)
//配置ADC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1, ENABLE);
//配置GPIO
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 ; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
//配置DMA
void DMA_Configuration(void)
{
  DMA_InitTypeDef DMA_InitStructure;
  DMA_DeInit(DMA1_Channel1); //将dma的通道寄存器设为默认值 
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;  //定义dma外设基地址 
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;  //外设作为数据传输的源 
  DMA_InitStructure.DMA_BufferSize = 1;   //dma缓存大小    
  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;  //工作在循环缓存模式,数据传输数目为0时,自动恢复配置初值 
  DMA_InitStructure.DMA_Priority = DMA_Priority_High; 
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;  //通道未被设置成内存到内存模式,与循环模式相对 
  DMA_Init(DMA1_Channel1, &DMA_InitStructure); //将DMA_InitStructure中指定的参数初始化dma的通道寄存器 

  DMA_Cmd(DMA1_Channel1, ENABLE);  //使能通道 
}
//配置ADC
void ADC_Configuration(void)
{
  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 = 1;
  ADC_Init(ADC1, &ADC_InitStructure);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, 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);
}

 


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]