aszrf 发表于 2016-1-18 15:48:02

DMA,采集adc,多通道,数码管闪烁厉害,关了dma就正常了?


int main(void)
{               
    u16 i,t;


      delay_init();                     //延时函数初始化         
      NVIC_Configuration();          //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
      LED_Init();      
      LCD_Init();                     //LED端口初始化
      IIC_Init();
      //TIM3_Int_Init(1249,35);//1Mhz的计数频率,计数到5000为500ms          Tout= ((arr+1)*(psc+1))/72=?us
      //TIM3_Int_Init(224,199);//1Mhz的计数频率,计数到2499为250ms          Tout= ((arr+1)*(psc+1))/72=?us
      TIM4_Int_Init(249,719);//1Mhz的计数频率,计数到5000为500ms          Tout= ((arr+1)*(psc+1))/72=?us
      GPIO_Configuration();
   // USART1_Configuration();
    Adcbydma_Init( )         ;
    USART2_Configuration();
      delay_ms(1000);
      LED1=0;
      LED2=0;
      LED3=0;
      LED4=0;

/**********测试程序******************************************/
      A_data=AT24CXX_ReadLenByte(10,1);
      A_data++;
    AT24CXX_WriteOneByte(10,A_data);                //指定地址写入一个字节
/********************************************************/

      Data_Reset();

         while(1)
      {         
      
                delay_ms(2);

/******测试程序*****111111111111***********/
                if(++test>100)                  
                  { F_data++;test=0;
                        if(F_data>1000)F_data=0;
                  }

               display_switch();         //显示程序 U A P L F      2015.1.5
             KEY_Scan()      ; //键盘扫描   2015.1.6
                if(times>150)
            {
                L_data=          (long)      ( cc*0.128+2.67 );
             U_data=(long)(         aa-87-70);
                A_data=         (long)         (bb*0.077+2.0);      
                times=0;
                }
                if(USART_RX_STA ==1 )
                  
      }         
}         
void Adcbydma_Init(void)
{
          GPIO_InitTypeDef GPIO_InitStructure;
          ADC_InitTypeDef ADC_InitStructure;
          DMA_InitTypeDef DMA_InitStructure;
          NVIC_InitTypeDef NVIC_InitStructure;
          TIM_TimeBaseInitTypeDef   TIM_TimeBaseStructure;


          /* Configure one bit for preemption priority */
         #if defined (VECT_TAB_RAM)
          /* Set the Vector Table base location at 0x20000000 */
          NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
      #elif defined(VECT_TAB_FLASH_IAP)
          NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000);
      #else/* VECT_TAB_FLASH*/
          /* Set the Vector Table base location at 0x08000000 */                        
          NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
          #endif



          /* Configure the NVIC Preemption Priority Bits */
          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
      
          /* Enable the RTC Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn ;                              
          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);

               
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
               
                /* Time Base configuration */
          TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

                TIM_TimeBaseStructure.TIM_Prescaler = 1;      
                TIM_TimeBaseStructure.TIM_Period = 22499;         
      
                TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
                TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;   
                TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
               
                TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
                TIM_Cmd(TIM3,ENABLE);
                TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);



         /* Enable ADC1 and GPIOA clock */
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);


          /* Configure PA.01 (ADC Channel1) as analog input -------------------------*/
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
          GPIO_Init(GPIOC, &GPIO_InitStructure);


               
          /* DMA channel1 configuration ----------------------------------------------*/
          DMA_DeInit(DMA1_Channel1);
          DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
          DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADCConvertedValue;
          DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
          DMA_InitStructure.DMA_BufferSize = 32*3+3;
          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_InitStructure.DMA_M2M = DMA_M2M_Disable;
          DMA_Init(DMA1_Channel1, &DMA_InitStructure);
      
          DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE); //开传输完中断
         
          /* Enable DMA channel1 */
          DMA_Cmd(DMA1_Channel1, ENABLE);
      
          RCC_ADCCLKConfig(RCC_PCLK2_Div6);
            /* ADC1 configuration ------------------------------------------------------*/
          ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
          ADC_InitStructure.ADC_ScanConvMode = ENABLE;
          ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
          ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO ;//ADC_ExternalTrigConv_None;
          ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
          ADC_InitStructure.ADC_NbrOfChannel = 3;
          ADC_Init(ADC1, &ADC_InitStructure);
          /* ADC1 regular channels configuration */
          ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_41Cycles5);   
          ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_41Cycles5);
         ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_41Cycles5);
          /* Enable ADC1 DMA */
          ADC_DMACmd(ADC1, ENABLE);
      
          /* Enable ADC1 */
          ADC_Cmd(ADC1, ENABLE);
          /* Enable Vrefint channel17 */
          //ADC_TempSensorVrefintCmd(ENABLE);
      
         
          /* Enable ADC1 reset calibaration register */   
          ADC_ResetCalibration(ADC1);
          /* Check the end of ADC1 reset calibration register */
          while(ADC_GetResetCalibrationStatus(ADC1));
      
         
          /* Start ADC1 calibaration */
          ADC_StartCalibration(ADC1);
          /* Check the end of ADC1 calibration */
          while(ADC_GetCalibrationStatus(ADC1));
            /* Start ADC1 Software Conversion */
      
      
                /* Enable ADC1 EOCinterrupts */
               
               
      //      ADC_ITConfig(ADC1, ADC_IT_EOC ,ENABLE);
      
      
          ADC_SoftwareStartConvCmd(ADC1, ENABLE);
      
          /* Test on DMA1 channel1 transfer complete flag */

}

一个主程序, 一个初始化dma中断,

发表于 2016-1-18 20:09:43

ADCConvertedValue这个数组多大的?可能是复位引起的吗?

aszrf 发表于 2016-1-19 16:55:45

安 发表于 2016-1-18 20:09
ADCConvertedValue这个数组多大的?可能是复位引起的吗?

是我中断里处理的信息太多了,导致数码管刷新太慢了

dsjsjf 发表于 2016-1-19 19:05:05

你难道中断里还有延时?

发表于 2016-1-20 10:10:03

中断中不要太多处理,会影响其他的中断。
页: [1]
查看完整版本: DMA,采集adc,多通道,数码管闪烁厉害,关了dma就正常了?