Chinaunix首页 | 论坛 | 博客
  • 博客访问: 421771
  • 博文数量: 55
  • 博客积分: 167
  • 博客等级: 入伍新兵
  • 技术积分: 1167
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-28 10:20
个人简介

一个算是正常的中国码农!

文章分类

全部博文(55)

文章存档

2014年(1)

2013年(31)

2012年(23)

我的朋友

分类: C/C++

2013-07-05 09:18:04

void ADC1_CH6_DMA_Config(void)
{
  ADC_InitTypeDef       ADC_InitStructure;
  ADC_CommonInitTypeDef ADC_CommonInitStructure;
  DMA_InitTypeDef       DMA_InitStructure;
  GPIO_InitTypeDef      GPIO_InitStructure;


  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);//???????é?±??
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);//???????é?±??


//  DMA_DeInit(DMA2_Stream0);
  /* DMA2 Stream0 channe0 configuration **************************************/
  DMA_InitStructure.DMA_Channel = DMA_Channel_0;  //???¨?¨?????????¨???????÷
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; //???¨???è???·??????
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC_ConvertedValue; //???¨???????·
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//???¨?????????è??????
  DMA_InitStructure.DMA_BufferSize = 2;//???¨DMA?????÷???ó??
  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?¨??????????????
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;  //???¨????fifo??????????????,fifo ???????¨????????????    
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;//???¨fifo??·§????
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //?è??????·?????
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  DMA_Init(DMA2_Stream0, &DMA_InitStructure);
  DMA_Cmd(DMA2_Stream0, ENABLE);


  /* Configure ADC1 Channel6 pin as analog input ******************************/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;//gpio???è????????°??????è????6.7?è????????????
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);


  /* ADC Common Init **********************************************************/
  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //????????????
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; //???ù????
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //????DMA
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//adc?????????±
  ADC_CommonInit(&ADC_CommonInitStructure); //?ù??adc???è?¨??


  /* ADC1 Init ****************************************************************/
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//?è????12??????
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;//???í???????????¨?è????
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//???í???????ù?????¨???????ù?????©
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//?¨?????í????·?
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//??????????????????
  ADC_InitStructure.ADC_NbrOfConversion = 2;//?è?????????ò×?????adc?¨????????2
  ADC_Init(ADC1, &ADC_InitStructure);


  /* ADC1 regular channe6 configuration *************************************/
  ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_3Cycles);
//?è?????¨??adc???ò×é???¨?????è????????×??????ò?????ù?±??
/*
*ADCx:???¨???ù??adc?¨??
*ADC_Channel?????¨???????¨????????
*Rank?????¨?????????ò1-16
*ADC_SampleTime_3Cycles?????¨?????±??
*/
  ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_3Cycles);
 /* Enable DMA request after last transfer (Single-ADC mode) */
  ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);//?????ò??????DMA??×???????


  /* Enable ADC3 DMA */
  ADC_DMACmd(ADC1, ENABLE);//?????ò????????dma


  /* Enable ADC3 */
  ADC_Cmd(ADC1, ENABLE);//????dma


}
双通道adc采集
阅读(1504) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~