原子哥,这是根据光盘例程改编的,为什么传输完成中断进入不了,下面是程序

2019-07-21 02:03发布

原子哥,这是根据光盘例程改编的,为什么传输完成中断进入不了,下面是程序:如果注释了这一部分:
  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0X01 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X03; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????
就进入不了void DMA1_Channel4_IRQHandler(void)这个函数里面,如果不注释这一部分,就进入不了这个主函数里面的这一部分:
if(DMA_GetFlagStatus(DMA1_FLAG_TC4)!=RESET) //?????¨??4?????ê??
{
DMA_ClearFlag(DMA1_FLAG_TC4);//?????¨??4?????ê??±ê??
 LED0=1;
 delay_ms(1800); 
break;
}

这是整个程序:
#include "stm32f10x.h"
#include "delay.h"
#include "usart.h"
#include "led.h"

extern u8 Counter;
u8 SendBuff[9]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};

DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
u16 DMA1_MEM_LEN;//±???DMA???????????????¤??    
//DMA1???÷?¨??????
//???????????????????¨??,???????ù?????????é????????
//???????÷->???è????/8???????í??/?????÷????????
//DMA_CHxMA?¨??CHx
//cpar:???è???·
//cmar:?????÷???·
//cndtr:?????????? 
void MYDMA_Config(DMA_Channel_TypeDef* DMA_CHx,u32 cpar,u32 cmar,u16 cndtr)
{

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //????DMA????

  DMA_DeInit(DMA1_Channel4);   //??DMA???¨??1?????÷???è???±????
DMA1_MEM_LEN=cndtr;
DMA_InitStructure.DMA_PeripheralBaseAddr = cpar;  //DMA???èADC?ù???·
DMA_InitStructure.DMA_MemoryBaseAddr = cmar;  //DMA?????ù???·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;  //????????·??ò????????????·????????è
DMA_InitStructure.DMA_BufferSize = cndtr;  //DMA?¨????DMA???????ó??
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?¨?? x???????????? 
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;  //DMA?¨??x?????è??????????????????
DMA_Init(DMA1_Channel4, &DMA_InitStructure);  //?ù??DMA_InitStruct?????¨????????????DMA???¨??USART1_Tx_DMA_Channel?ù±ê?????????÷



  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0X01 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X03; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷
//
DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE);


//????????DMA????
void MYDMA_Enable(DMA_Channel_TypeDef*DMA_CHx)


  DMA_Cmd(DMA1_Channel4, DISABLE );  //??±?USART1 TX DMA1 ?ù???????¨??      
  DMA_SetCurrDataCounter(DMA1_Channel4,9);//DMA?¨????DMA???????ó??
  DMA_Cmd(DMA1_Channel4, ENABLE);  //????USART1 TX DMA1 ?ù???????¨?? 
}  

u8 Counter=5;
 int main(void)
 {
delay_init();     //???±??????????  
NVIC_Configuration(); //?è??NVIC????·?×é2:2??????????????2???ì????????
uart_init(9600); //?®??????????9600
  LED_Init();     //LED??????????
MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR,(u32)SendBuff,9);//DMA1?¨??4,???è???®??1,?????÷??SendBuff,?¤??5168. 
LED0=0;
LED1=0;
  while(1)
{  
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); //?????®??1??DMA·??? 
MYDMA_Enable(DMA1_Channel4);//????????DMA??????
while(1)

if(Counter==0)
LED1=1;
if(DMA_GetFlagStatus(DMA1_FLAG_TC4)!=RESET) //?????¨??4?????ê??
{
DMA_ClearFlag(DMA1_FLAG_TC4);//?????¨??4?????ê??±ê??
 LED0=1;
 delay_ms(1800); 
break;
}
LED0=0;
delay_ms(1800);
}
}
 }

 
void DMA1_Channel4_IRQHandler(void)

LED1=1;
delay_ms(1800);
if(DMA_GetITStatus(DMA1_IT_TC4))  //??????????·??ê??
{
Counter=DMA_GetCurrDataCounter(DMA1_Channel4); //???????????à????
LED1=0;delay_ms(1800);
DMA_ClearITPendingBit(DMA1_IT_GL4); //????????????±???
  }
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。