我现在在做一个ADC规则通道采集多路感应电压(ADC1和ADC2),我用的是软件自身触发的方式,我一共有八个通道,ADC1,ADC2各四个,用的是软件触发,我也设置一个中断标志sign(初始为0),进入DMA(DMA1_Channel1)后sign=1,同时进行相应的数据处理,在DMA_ClearITPendingBit(DMA_IT_TC)后sign置0,出DMA中断后继续进行AD采集,但我发现ADC就采集过一次,DMA中断也只进入过一次,我也不知问题在哪里 #include "ADC12.h" #include "UART.h" #include "systick.h" // **************************************************************************** // 常 数 宏 定 义 * #define ADC1_DR_Address ((uint32_t)0x4001244C) __IO uint32_t ADC12_ValueBuffer[4]; #define N 7 // **************************************************************************** // 函数名称: // 功能描述: // 输 入: // 输 出: // 全局变量: // 调用模块: void ACD12Init(void) { ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; NVIC_InitTypeDef NVIC_InitStructure ; GPIO_InitTypeDef GPIO_InitStructure; /* GPIOC Configurationin6, 7, 8 and 9 as alternate function AIN */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3| GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_6| GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); //DMA /* Enable DMA1 and DMA2 clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC12_ValueBuffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 4; //控制每次ADC采集的数据个数,由于是双通道,即每个通道采集4*2/N个数据,N为通道个数 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 Channel1 */ //DMA_Cmd(DMA1_Channel1, ENABLE); DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE) ; /* ADC1 configuration ------------------------------------------------------*/ RCC_ADCCLKConfig(RCC_PCLK2_Div6); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE ); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE ); //ADC1,ADC2时钟使能 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; 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 = 4; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, AD_Channel,1, ADC_SampleTime_7Cycles5 ); //PB1,配置为同步规则模式,ADC1,ADC2,转换顺序为1,2,3,4.。。。 ADC_RegularChannelConfig(ADC1, AD_Channe3,2, ADC_SampleTime_7Cycles5 ); //PA7 ADC_RegularChannelConfig(ADC1, AD_Channe5,3, ADC_SampleTime_7Cycles5 ); //PA5 ADC_RegularChannelConfig(ADC1, AD_Channe7,4, ADC_SampleTime_7Cycles5 ); //PA4 /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC2 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; 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 = 4; ADC_Init(ADC2, &ADC_InitStructure); /* ADC2 regular channels configuration */ ADC_RegularChannelConfig(ADC2, AD_Channe8,4, ADC_SampleTime_7Cycles5 ); //Vref ADC_RegularChannelConfig(ADC2, AD_Channe6,3, ADC_SampleTime_7Cycles5 ); //PA4 ADC_RegularChannelConfig(ADC2, AD_Channe4,2, ADC_SampleTime_7Cycles5 ); //PA6 ADC_RegularChannelConfig(ADC2, AD_Channe2,1, ADC_SampleTime_7Cycles5 ); //PC5 /* Enable ADC2 external trigger conversion */ ADC_ExternalTrigConvCmd(ADC2, ENABLE); //外部触发源来自ADC1的规则组多路器(由/* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 reset calibration register */ ADC_ResetCalibration(ADC2); /* Check the end of ADC2 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC2 calibration */ ADC_StartCalibration(ADC2); /* Check the end of ADC2 calibration */ while(ADC_GetCalibrationStatus(ADC2)); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable Vrefint channel17 */ ADC_TempSensorVrefintCmd(ENABLE); /* Enable ADC1 reset calibration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ //ADC_ExternalTrigConvCmd(ADC1, ENABLE); /* Test on DMA1 channel1 transfer complete flag */ //while(RESET==DMA_GetFlagStatus(DMA1_FLAG_TC1)); //容易卡在这里我就屏蔽了 /* Clear DMA1 channel1 transfer complete flag */ //DMA_ClearFlag(DMA1_FLAG_TC1); //while(RESET==DMA_GetFlagStatus(DMA1_FLAG_TC1)); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1 ; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0 ; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ; NVIC_Init(&NVIC_InitStructure); //TIM_Cmd(TIM4,ENABLE); return; } // ***************************************************************************** // 函数名称: // 功能描述: // 输 入: // 输 出: // 全局变量: // 调用模块: extern uint8_t sign ; // 将7路外部AD口的数据分为七组,依次编号为0,1,2,3..... uint16_t p,j,k=0; uint16_t Value1[N],Value2[N],Value3[N],Value4[N],Value5[N],Value6[N],Value7[N]; uint32_t Sum0=0,Sum1=0,Sum2=0,Sum3=0,Sum4=0,Sum5=0,Sum6=0,Sum7=0; void DMA1_Channel1_IRQHandler(void) { if(DMA_GetITStatus(DMA_IT_TC)!= RESET) { p++; //想看看进入过中断几次 sign = 1; //sign=1,表示七通道采集轮询一次完成 DMA_Cmd(DMA1_Channel1, DISABLE); //ADC_SoftwareStartConvCmd(ADC1, DISABLE); for(k=0,j=0;k>16)&0x0000ffff))|0x1000; Sum2+=Value2[j]; Value3[j]=((ADC12_ValueBuffer[k+1]&0x0000ffff))|0x2000; Sum3+=Value3[j]; Value4[j]=((ADC12_ValueBuffer[k+1]>>16)&0x0000ffff)|0x3000; Sum4+=Value4[j]; Value5[j]=(ADC12_ValueBuffer[k+2]&0x0000ffff)|0x4000; Sum5+=Value5[j]; Value6[j]=((ADC12_ValueBuffer[k+2]>>16)&0x0000ffff)|0x5000; Sum6+=Value6[j]; Value7[j]=(ADC12_ValueBuffer[k+3]&0x0000ffff)|0x6000; Sum7+=Value7[j]; } //DMA_Configuration() ; //DelayMS(100); } DMA_Cmd(DMA1_Channel1, ENABLE); //ADC_SoftwareStartConvCmd(ADC1, ENABLE); DMA_ClearITPendingBit(DMA_IT_TC); sign = 0 ; } |
回复:ADC同步规则通道采集