ADC+DMA程序始终进不了DMA2_Stream1_IRQHandler

2019-07-20 06:46发布

  ADC+DMA程序始终进不了DMA2_Stream1_IRQHandler,也不知道哪里出错了,还请大神指点啊!


这个是初始化设置
  GPIO_InitTypeDef  GPIO_InitStructure;
  ADC_CommonInitTypeDef ADC_CommonInitStructure;
  ADC_InitTypeDef       ADC_InitStructure;
  DMA_InitTypeDef       DMA_InitStructure;
  NVIC_InitTypeDef      NVIC_InitStructure;
  // dma2 stream1 reset
  DMA_DeInit(DMA2_Stream1);
  //wait dma2 configure enable
  while (DMA_GetCmdStatus(DMA2_Stream1) != DISABLE){;}   
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  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_Normal;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  //adc3
  DMA_InitStructure.DMA_Channel = DMA_Channel_2;  
  DMA_InitStructure.DMA_PeripheralBaseAddr =  (u32)&ADC3->DR;;
  DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&adc3_result_original;
  DMA_InitStructure.DMA_BufferSize = cbAdcMaxNum;   
  DMA_Init(DMA2_Stream1, &DMA_InitStructure);  
  DMA_Cmd(DMA2_Stream1, ENABLE);
  //adc3
  NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  //adc3
  DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);   
   
  // enable adc1,adc2,adc3, dma2 and gpio clocks
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2|RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1| RCC_APB2Periph_ADC2|RCC_APB2Periph_ADC3, ENABLE);
  // configure ADC1 Channel3,4,5,6 pin as analog input
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  // configure ADC1 Channel0,1 pin as analog input
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  // configure ADC3 Channel0 pin as analog input
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  
  // reset adc1
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE);  
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE);
  // reset adc3
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,ENABLE);  
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,DISABLE);   
  // adc common initialize
  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//ADCCLK=PCLK2/4=84/4=21Mhz
  ADC_CommonInit(&ADC_CommonInitStructure);
  // adc3 initianlize
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;  
  ADC_InitStructure.ADC_NbrOfConversion = 1;
  ADC_Init(ADC3, &ADC_InitStructure);
  // adc3 regular configuration
  ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 1, ADC_SampleTime_56Cycles);
    // enable dma request after last transfer (multi-adc mode)
  //ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
  
  ADC_Cmd(ADC3, ENABLE);
  //ADC_ITConfig(ADC3,ADC_IT_EOC,ENABLE);


DMA中断程序
void DMA2_Stream1_IRQHandler(void)
{
  u8  bIndex,bTemp;
  u16 sAdcValue;
  u32 wAdcSumTemp=cwParaReset;

  if(DMA_GetFlagStatus(DMA2_Stream1,DMA_IT_TCIF1))
  {
    //ADC_SoftwareStartConvCmd(ADC3, DISABLE);
    DMA_ClearFlag(DMA2_Stream1,DMA_IT_TCIF1);
  }
}

主程序
      vWdtReload();
      vTimDlyMs(100);
    //disable dma2
    DMA_Cmd(DMA2_Stream1, DISABLE);
    //make sure dma can be setting
    while (DMA_GetCmdStatus(DMA2_Stream1) != DISABLE){;}
    //set dma counter
    DMA_SetCurrDataCounter(DMA2_Stream1, cbAdcMaxNum);
    //enable dma2
    DMA_Cmd(DMA2_Stream1, ENABLE);   
//    //start dma2 interrupt
//    DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);      
     
     ADC_SoftwareStartConv(ADC3);  //ʹÄÜÖ¸¶¨µÄADC1µÄÈí¼þת»»Æô¶¯¹¦ÄÜ
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
正点原子
1楼-- · 2019-07-20 08:52
 精彩回答 2  元偷偷看……
xiongliangxcl
2楼-- · 2019-07-20 09:54
正点原子 发表于 2018-8-7 16:00
参考这里:http://www.openedv.com/forum.php?mod=viewthread&tid=276626

原子哥,你发的例子程序我有,我目前想要使用的是单次ADC触发DMA的中断,发现除了第一次能够触发成功后面的好像都不行,当然我贴出来的帖子里面也少了一个东西,那就是       
                ADC_DMACmd(ADC1, ENABLE);        
                ADC_DMACmd(ADC3, ENABLE);
xiongliangxcl
3楼-- · 2019-07-20 13:58
正点原子 发表于 2018-8-7 16:00
参考这里:http://www.openedv.com/forum.php?mod=viewthread&tid=276626

这个问题没有解决啊!
xiongliangxcl
4楼-- · 2019-07-20 18:44
 精彩回答 2  元偷偷看……

一周热门 更多>