本帖最后由 watercici 于 2018-7-30 17:19 编辑
带DMA的AD,同一个程序,打开DMA_Channel1就能进入DMA中断,可是换成DMA_Channel2就不行了,希望
帮我看看。程序如下: 在线等,谢谢。是不是ADC1只能用DMA_Channel1通道???
- void DMA1_Channel2_IRQHandler(void)
- {
- if(DMA_GetFlagStatus(DMA1_FLAG_TC1)==SET)
- {
- dma1_irq_status1 = EVENT_PENDING;
- DMA_ClearFlag(DMA1_FLAG_TC1);
- Stop_adc();
- }
- }
复制代码- void init_adc()
- {
- ADC_InitTypeDef adc_obj;
- GPIO_InitTypeDef gpio_obj;
- DMA_InitTypeDef dma_obj;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
- //NVIC config
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /*DMA1 channel2 configuration*/
- DMA_DeInit(DMA1_Channel2);
- dma_obj.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
- dma_obj.DMA_MemoryBaseAddr = (u32)&sample_value;
- dma_obj.DMA_DIR = DMA_DIR_PeripheralSRC;
- dma_obj.DMA_BufferSize = SAMPLE_SZIE;
- dma_obj.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- dma_obj.DMA_MemoryInc = DMA_MemoryInc_Enable;
- dma_obj.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- dma_obj.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- dma_obj.DMA_Mode = DMA_Mode_Normal;
- dma_obj.DMA_Priority = DMA_Priority_VeryHigh;
- dma_obj.DMA_M2M = DMA_M2M_Disable;
-
- DMA_Init(DMA1_Channel2 , &dma_obj);
-
- /*Enable DMA1 channel2*/
- DMA_Cmd(DMA1_Channel2 , ENABLE);
- DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
- //periph clcok
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
- //gpio config
- gpio_obj.GPIO_Pin = GPIO_Pin_1;
- gpio_obj.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOA , &gpio_obj);
- ADC_DeInit(ADC1);
- /*ADC1 configuration*/
- adc_obj.ADC_Mode = ADC_Mode_Independent;
- adc_obj.ADC_ScanConvMode = DISABLE;
- adc_obj.ADC_ContinuousConvMode = ENABLE;
- adc_obj.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
- adc_obj.ADC_DataAlign = ADC_DataAlign_Right;
- adc_obj.ADC_NbrOfChannel = 1;
- ADC_Init(ADC1 , &adc_obj);
- RCC_ADCCLKConfig(RCC_PCLK2_Div8); //9Mhz
- ADC_RegularChannelConfig(ADC1 , ADC_Channel_1 , 1 , ADC_SampleTime_1Cycles5);
- /*Enable ADC1 DMA*/
- ADC_DMACmd(ADC1 , ENABLE);
- /*Enable ADC1*/
- ADC_Cmd(ADC1 , ENABLE);
- ADC_ResetCalibration(ADC1);
- while(ADC_GetResetCalibrationStatus(ADC1));
-
- ADC_StartCalibration(ADC1);
- while(ADC_GetCalibrationStatus(ADC1));
-
- ADC_SoftwareStartConvCmd(ADC1 , ENABLE);
- }
复制代码
|
评分
查看全部评分
像你说的想多路采集,一直使用ADC1的CH1,把采集频率提高,用轮询的方式实现。
评分
查看全部评分
哦,好的,谢谢