使用STM32F4的ADC采集4路电压信号,通过DMA传输,可是串口助手一直不能接受数据

2019-03-23 16:23发布

应该是if(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_TCIF0)!=RESET)一直不通过,但是不知道为什么,希望大家帮忙看看


  1. 主程序
  2. int main(void)
  3. {
  4.   delay_init(168);
  5.         uart_init(115200);
  6.   Adc_Init();
  7.         LED_Init();
  8.         delay_ms(10);
  9.         MYDMA_Config(DMA2_Stream0,(u32)&ADC1->DR,(u32)&ADC_V);
  10.         while(1)
  11.         {
  12.           if(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_TCIF0)!=RESET)
  13.     {
  14.                         LED0=0;
  15.       printf("adc0=%d  ",ADC_V[0]);
  16.       printf("adc1=%d  ",ADC_V[1]);
  17.                         printf("adc0=%d  ",ADC_V[2]);
  18.       printf("adc1=%d  ",ADC_V[3]);
  19.      DMA_ClearFlag(DMA2_Stream0,DMA_FLAG_TCIF0);
  20.     }
  21.                 delay_ms(1);
  22.         }
  23. }

  24. ADC程序
  25. void  Adc_Init(void)
  26. {   
  27.   GPIO_InitTypeDef  GPIO_InitStructure;
  28.         ADC_CommonInitTypeDef ADC_CommonInitStructure;
  29.         ADC_InitTypeDef       ADC_InitStructure;
  30.        
  31.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
  32.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó


  33.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_5|GPIO_Pin_6;
  34.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
  35.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
  36.   GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ  

  37.         RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE);          //ADC1¸′λ
  38.         RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE);        //¸′λ½áêø         

  39.        
  40.   ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//¶àá¢Ä£ê½
  41.   ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
  42.   ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
  43.   ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//Ô¤·ÖÆμ4·ÖÆμ¡£ADCCLK=PCLK2/4=84/4=21Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
  44.   ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
  45.        
  46.   ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
  47.   ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  48.   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  49.   ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//½ûÖ1′¥·¢¼ì2a£¬ê1óÃèí¼t′¥·¢
  50.   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë       
  51.   ADC_InitStructure.ADC_NbrOfConversion = 4;
  52.   ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
  53.        
  54.         ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_480Cycles );        //ADC1,ADCí¨μà,480¸öÖüÆú,ìá¸ß2éÑùê±¼ä¿éòÔìá¸ß¾«è·¶è                       
  55.   ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_480Cycles );
  56.   ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_480Cycles );
  57.   ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_480Cycles );       
  58.        
  59.        
  60.         ADC_Cmd(ADC1, ENABLE);       
  61.         ADC_SoftwareStartConv(ADC1);
  62.         ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);
  63.         ADC_DMACmd(ADC1,ENABLE);
  64.   

  65. }

  66. DMA程序
  67. void MYDMA_Config(DMA_Stream_TypeDef *DMA_Streamx,u32 par,u32 mar)
  68. {

  69.         DMA_InitTypeDef  DMA_InitStructure;
  70.        
  71.         if((u32)DMA_Streamx>(u32)DMA2)//μÃμ½μ±Ç°streamêÇêôóúDMA2»1êÇDMA1
  72.         {
  73.           RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);//DMA2ê±Öóê1Äü
  74.                
  75.         }else
  76.         {
  77.           RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1ê±Öóê1Äü
  78.         }
  79.   DMA_DeInit(DMA_Streamx);
  80.        
  81.         while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){}//μè′yDMA¿éÅäÖÃ
  82.        
  83.   /* ÅäÖÃ DMA Stream */
  84.   DMA_InitStructure.DMA_Channel = DMA_Channel_0;  //í¨μàÑ¡Ôñ
  85.   DMA_InitStructure.DMA_PeripheralBaseAddr = par;//DMAíaéèμØÖ·
  86.   DMA_InitStructure.DMA_Memory0BaseAddr = mar;//DMA ′æ′¢Æ÷0μØÖ·
  87.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//íaéèμ½′æ′¢Æ÷
  88.   DMA_InitStructure.DMA_BufferSize = 100;//êy¾Y′«êäá¿
  89.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//íaéè·ÇÔöá¿Ä£ê½
  90.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//′æ′¢Æ÷Ôöá¿Ä£ê½
  91.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//íaéèêy¾Y3¤¶è:16λ
  92.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//′æ′¢Æ÷êy¾Y3¤¶è:16λ
  93.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//Ñ-»·Ä£ê½
  94.   DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//ÖDμèóÅÏ輶
  95.   DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
  96.   DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  97.   DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//′æ′¢Æ÷í»·¢μ¥′Î′«êä
  98.   DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//íaéèí»·¢μ¥′Î′«êä
  99.   DMA_Init(DMA_Streamx, &DMA_InitStructure);//3õê¼»ˉDMA Stream

  100.         DMA_Cmd(DMA_Streamx, ENABLE);                      //¿aÆôDMA′«êä
  101.                

  102. }       
复制代码
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。