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_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//ê1ÄüGPIOCê±Öó
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE); //ê1ÄüADC2ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); //ê1ÄüADC3ê±Öó
//Ïè3õê¼»ˉADC1í¨μà5 IO¿ú
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4;//ê1ÄüáËADC1μÄ0£¬1£¬2í¨μà
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;//ê1ÄüáËADC10£11£¬¬12í¨μà
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOC, &GPIO_InitStructure);//3õê¼»ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;//ê1ÄüáËADC10£11£¬¬12í¨μà
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOF, &GPIO_InitStructure);//3õê¼»ˉ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //ADC1¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //¸′λ½áêø
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2,ENABLE); //ADC2¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2,DISABLE); //¸′λ½áêø
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,ENABLE); //ADC2¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,DISABLE); //¸′λ½áêø
ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult;//¶àá¢Ä£ê½
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_15Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2; //DMAÄ£꽶t
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//Ô¤·ÖÆμ4·ÖÆμ¡£ADCCLK=PCLK2/4=84/4=21Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//é¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//¿aÆôá¬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;//3¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD3
ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_Init(ADC2, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_Init(ADC3, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);//¿aÆôAD×a»»Æ÷
ADC_DMACmd(ADC2, ENABLE);
ADC_Cmd(ADC2, ENABLE);//¿aÆôAD×a»»Æ÷
ADC_DMACmd(ADC3, ENABLE);
ADC_Cmd(ADC3, ENABLE);//¿aÆôAD×a»»Æ÷
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_3Cycles);
//ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_3Cycles);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);
// ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 2, ADC_SampleTime_3Cycles);
//ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 3, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 1, ADC_SampleTime_3Cycles);
//ADC_RegularChannelConfig(ADC3, ADC_Channel_5, 2, ADC_SampleTime_3Cycles);
//ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 3, ADC_SampleTime_3Cycles);
ADC_SoftwareStartConv(ADC1);
ADC_SoftwareStartConv(ADC2);
ADC_SoftwareStartConv(ADC3);
}
/*配置DMA*/
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_Word;//íaéèêy¾Y3¤¶è:16λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;//′æ′¢Æ÷êy¾Y3¤¶è:16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;// ê1óÃÑ-»·Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//ÖDμèóÅÏ輶
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
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配置
MYDMA_Config(DMA2_Stream0,DMA_Channel_0,(u32)&ADC->CDR,(u32)&adcx,6);
MYDMA_Enable(DMA2_Stream0,6);
目前的设定是ADC1 3.3V也就是0xFF,ADC2是0V也就是0X00左右,ADC3是3.3V
选择的是ADC的规则同步模式,DMA模式2,应该是第一个数据是ADC1,2的,第二个是ADC1,3的,第三个是3,2的,可是我这个到了第二组之后就一直是1.3的值不变了,这是为什么
一周热门 更多>