DMA中断进不去。

2019-07-20 02:41发布

    如题,中断进不去。小弟在做串口的DMA实验,参照原子哥的程序,发现在函数里等待DMA传输完成之后清零太浪费时间,于是
使能了DMA传输完成中断,在中断里清零。(不打开中断,在主程序里while检测发送完成之后再清零标志位是可以的)。

代码如下:
中断分组配置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

DMA中断服务函数:
/************************************************************
***************************************************************/
void DMA2_Stream7_IRQHandler(void)  
{  
if(DMA_GetFlagStatus(DMA2_Stream7,DMA_FLAG_TCIF7)!=RESET)//????DMA2_Steam7?????ê??

DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7);//????DMA2_Steam7?????ê??±ê??
}
}




DMA初始化函数:

void Usart_DMA_Init(DMA_Stream_TypeDef *DMA_Streamx,u32 chx,u32 par,u32 mar,u16 ndtr)
{
DMA_InitTypeDef  DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

if((u32)DMA_Streamx>(u32)DMA2)//?????±?°stream??????DMA2????DMA1
{
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);//DMA2?±?????? 

}else 
{
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1?±?????? 
}
  DMA_DeInit(DMA_Streamx);

while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){}//????DMA?????? 

  /* ???? DMA Stream */
  DMA_InitStructure.DMA_Channel = chx;  //?¨??????
  DMA_InitStructure.DMA_PeripheralBaseAddr = par;//DMA???è???·
  DMA_InitStructure.DMA_Memory0BaseAddr = mar;//DMA ?????÷0???·
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//?????÷?????è????
  DMA_InitStructure.DMA_BufferSize = ndtr;//?????????? 
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//???è·?????????
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//?????÷????????
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//???è?????¤??:8??
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;//?????÷?????¤??:8??
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;// ???????¨???? 
  DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//??????????
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//?????÷??·?????????
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//???è??·?????????
  DMA_Init(DMA_Streamx, &DMA_InitStructure);//??????DMA Stream

DMA_ITConfig(DMA2_Stream7,DMA_IT_TC,ENABLE);//???????ê??????

NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream7_IRQn;  
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  
NVIC_Init(&NVIC_InitStructure); 
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。