高级会员
- 积分
- 844
- 金钱
- 844
- 注册时间
- 2016-1-5
- 在线时间
- 208 小时
|
楼主 |
发表于 2016-1-27 12:09:08
|
显示全部楼层
本帖最后由 明天起飞吧 于 2016-1-27 12:12 编辑
[mw_shl_code=c,true]void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
//Ïè3õê¼»ˉADC1í¨μà5 IO¿ú
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//PA5 í¨μà5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //ADC1¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //¸′λ½áêø
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//¶àá¢Ä£ê½
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //--DMAÄ£ê½1
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;//Ô¤·ÖÆμ2·ÖÆμ¡£ADCCLK=PCLK2/2=72/2=36Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE;//--·Çé¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//--á¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//½ûÖ1′¥·¢¼ì2a£¬ê1óÃèí¼t′¥·¢
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë
ADC_InitStructure.ADC_NbrOfConversion = 1;//1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_EOCOnEachRegularChannelCmd(ADC1,DISABLE);//ADC_CR2_EOCSÿ¸ö1æÔò×a»»DòáD½áêøê±EOCÖÃò»
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_480Cycles ); //ADC1,ADCí¨μà,480¸öÖüÆú,ìá¸ß2éÑùê±¼ä¿éòÔìá¸ß¾«è·¶è
ADC_DMACmd(ADC1, ENABLE); //ADC_CR2_DMAê1ÄüADC1μÄDMA′«êä £¬Ô-±¾ADCéÏûóDμÄ£¬×¢òaìí¼ó
ADC_Cmd(ADC1, ENABLE);//ADC_CR2_ADON¿aÆôAD×a»»Æ÷ Ïè¿aÆôDMAÔù¿aADC
ADC_SoftwareStartConv(ADC1);//ADC_CR2_SWSTARTê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»1|Äü
ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);//ADC_CR2_DDS Ö»òaêy¾Y×a»»±ã»á·¢3öDMAÇëÇó
}
[/mw_shl_code][mw_shl_code=c,true]void MYDMA_Config(DMA_Stream_TypeDef *DMA_Streamx,u32 chx,u32 par,u32 mar,u16 ndtr)
{
DMA_InitTypeDef DMA_InitStructure;
if((u32)DMA_Streamx>(u32)DMA2)//μÃμ½μ±Ç°streamêÇêôóúDMA2»1êÇDMA1
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);//DMA2ê±Öóê1Äü
}else
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1ê±Öóê1Äü
}
DMA_DeInit(DMA_Streamx);//Çå¿ÕËùóDÅäÖã¬Çå¿Õ±ê־λ
while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){}//μè′yDMA¿éÅäÖà CR¼Ä′æÆ÷ÏÂENÎa0ê±2Å¿éòÔÅäÖÃ
/* ÅäÖÃ DMA Stream */
DMA_InitStructure.DMA_Channel = chx; //í¨μàÑ¡Ôñ
DMA_InitStructure.DMA_PeripheralBaseAddr = par;//DMAíaéèμØÖ·
DMA_InitStructure.DMA_Memory0BaseAddr = mar;//DMA ′æ′¢Æ÷0μØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//--íaéèμ½′æ′¢Æ÷Ä£ê½
DMA_InitStructure.DMA_BufferSize = ndtr;//êy¾Y′«êäá¿
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//íaéè·ÇÔöá¿Ä£ê½
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//′æ′¢Æ÷Ôöá¿Ä£ê½
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//íaéèêy¾Y3¤¶è:16λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//′æ′¢Æ÷êy¾Y3¤¶è:16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;// ê1óÃÑ-»·Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//¸ßμèóÅÏ輶
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;//FIFOμÄíêÕûèYá¿
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//′æ′¢Æ÷í»·¢μ¥′Î′«êä
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//íaéèí»·¢μ¥′Î′«êä
DMA_Init(DMA_Streamx, &DMA_InitStructure);//3õê¼»ˉDMA Stream
DMA_Cmd(DMA2_Stream0, ENABLE);//DMA_SxCR_EN
//DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE); /* +DMAÖD¶Ï¿a*/
} [/mw_shl_code]
|
|