我使用双USART USART1 采用DMA1 Channel4 USART2 采用 DMA1 Channel5 但是 Channel5的中断一直进不去,我把2路通道互换,Channel5中断还是进不去,不知道什么原因 /*---------------------------------------------------------------------*/ /* INIT IO */ /* INPUT:NONE */ /* OUTPUT:NONE */ /*---------------------------------------------------------------------*/ void bsp_uart_init(){ //GPIO¶Ë¿ÚÉèÖà GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef UART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //ʹÄÜUART1 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //ʹÄÜUART1 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //?? PB,PE ???? ; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn; //???????1?? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //???? NVIC_Init(&NVIC_InitStructure); //??? //UART1_TX GPIOA.9 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_9; //PA.9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//GPIO_Mode_IN_FLOATING;//¸¡¿ÕÊäÈë GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.9 //UART1_RX GPIOA.10³õʼ»¯ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_10;//PA10 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIOA.10 /************DMA1_Channel2***********/ DMA_DeInit(DMA1_Channel4); //??7???,??UART1??? DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&USART1->DR; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)UART_TX_BUF; //???? UART1_TxBuff DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //??:??-->?? ????? DMA_InitStructure.DMA_BufferSize = 0; //???? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //????? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //???? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//??????:?? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //??????:?? DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //DMA??:????,??? DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //???:? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //memory-to-memory ?? DMA_Init(DMA1_Channel4, &DMA_InitStructure); DMA_ClearFlag(DMA1_FLAG_TC4); DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE); //DMA?????? //UART1 NVIC ÅäÖà // NVIC_InitStructure.NVIC_IRQChannel = UART1_IRQn; // NVIC_InitStructure.NVIC_IRQChannelPriority = 3; //×ÓÓÅÏȼ¶3 // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ // NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷ //UART ³õʼ»¯ÉèÖà // GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_3); // GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_3); UART_InitStructure.USART_BaudRate = BAUD_9600;//´®¿Ú²¨ÌØÂÊ UART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ UART_InitStructure.USART_StopBits = USART_StopBits_1;//Ò»¸öֹͣλ UART_InitStructure.USART_Parity = USART_Parity_No;//ÎÞÆæżУÑéλ UART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ UART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ÊÕ·¢Ä£Ê½ USART_Init(USART1, &UART_InitStructure); //³õʼ»¯´®¿Ú1 // UART_ITConfig(UART1, UART_IT_RXIEN, ENABLE);//¿ªÆô´®¿Ú½ÓÊÜÖÐ¶Ï USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);//½«UART1µÄ·¢ËÍDMA¹¦ÄÜ´ò¿ª USART_DMACmd(USART1,USART_DMAReq_Rx,DISABLE);//½«UART1µÄ·¢ËÍDMA¹¦ÄÜ´ò¿ª USART_Cmd(USART1, ENABLE); //ʹÄÜ´®¿Ú1 DMA_Cmd(DMA1_Channel4, ENABLE); // ---------------------- ////////------------------UART2-------------------------------------/////////// // RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE); //UART2 // RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE); //UART2 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //????1???? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //??????? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //?????? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //????1?? NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn; //???????1?? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //???? NVIC_Init(&NVIC_InitStructure); DMA_DeInit(DMA1_Channel5); // ????? DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&USART2->DR);// ??????????? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)UART2_TX_BUF; // ?????????? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // ???????,????? -> ????? DMA_InitStructure.DMA_BufferSize = 0; // ????????,?????????0,???????????,??????? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // ??????????,??????DMA????? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // ??????????? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; // ??????8?,1??? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; // ??????8?,1??? DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // ?????? DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; // ????? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // ????????DMA?? DMA_Init(DMA1_Channel5, &DMA_InitStructure); // ???? DMA_ClearFlag(DMA1_FLAG_GL5); // ??DMA????//UART2?TX?DMA1??7 DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE); // ????DMA???? UART_InitStructure.USART_BaudRate = BAUD_115200;//´®¿Ú²¨ÌØÂÊ UART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ UART_InitStructure.USART_StopBits = USART_StopBits_1;//Ò»¸öֹͣλ UART_InitStructure.USART_Parity = USART_Parity_No;//ÎÞÆæżУÑéλ UART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ UART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ÊÕ·¢Ä£Ê½ USART_Init(USART2, &UART_InitStructure); //³õʼ»¯´®¿Ú1 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//¿ªÆô´®¿Ú½ÓÊÜÖÐ¶Ï USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);//½«UART1µÄ·¢ËÍDMA¹¦ÄÜ´ò¿ª USART_DMACmd(USART2,USART_DMAReq_Rx,DISABLE);//½«UART1µÄ·¢ËÍDMA¹¦ÄÜ´ò¿ª USART_Cmd(USART2, ENABLE); //ʹÄÜ´®¿Ú1 // USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);//¿ªÆô´®¿Ú½ÓÊÜÖÐ¶Ï DMA_Cmd(DMA1_Channel5, ENABLE); // ????DMA??,?????? } /*---------------------------------------------------------------------*/ /* INIT IO */ /* INPUT:NONE */ /* OUTPUT:NONE */ /*---------------------------------------------------------------------*/ unsigned char UART1_DMA_SendDat(unsigned char *DataAddress,unsigned int len) { unsigned int len2; usart_tx_finish &= ~UART1_FLAG; while(len>(UART_TX_LEN-UART1_TxCnt))//?????????????????????????? { if(usart_tx_finish&UART1_FLAG)break; } memcpy(UART_TX_BUF+UART1_TxCnt,DataAddress,len); UART1_DMA_TX_CH->CCR &= (unsigned int)(~UART1_DMA_TX_EN);//??DMA??1 len2=UART1_TxCnt-UART1_DMA_TX_CH->CNDTR; //?????????? UART1_TxCnt+=len; //UART1_TxCnt?????,?????UART1_TxBuff???????? UART1_DMA_TX_CH->CMAR = (u32)UART_TX_BUF+len2;//???? UART1_DMA_TX_CH->CNDTR = UART1_DMA_TX_CH->CNDTR+len;//??DMA ?????? UART1_DMA_TX_CH->CCR |= UART1_DMA_TX_EN;//??DMA??1 while((usart_tx_finish&UART1_FLAG)==0); return 1; } /*---------------------------------------------------------------------*/ /* INIT IO */ /* INPUT:NONE */ /* OUTPUT:NONE */ /*---------------------------------------------------------------------*/ void DMA1_Channel4_IRQHandler(void) { if(DMA_GetITStatus(UART1_DMA_TX_TC) == SET)//????????? { DMA1->IFCR = UART1_DMA_TX_TC; //?????? UART1_TxCnt=0;//?????? usart_tx_finish |= UART1_FLAG; } } /*---------------------------------------------------------------------*/ /* INIT IO */ /* INPUT:NONE */ /* OUTPUT:NONE */ /*---------------------------------------------------------------------*/ unsigned char UART2_DMA_SendDat(unsigned char *DataAddress,unsigned int len) { unsigned int len2; usart2_tx_finish &= ~UART1_FLAG; while(len>(UART2_TX_LEN-UART2_TxCnt))//?????????????????????????? { if(usart2_tx_finish&UART2_FLAG)break; } memcpy(UART2_TX_BUF+UART2_TxCnt,DataAddress,len); UART2_DMA_TX_CH->CCR &= (unsigned int)(~UART2_DMA_TX_EN);//??DMA??1 len2=UART2_TxCnt-UART2_DMA_TX_CH->CNDTR; //?????????? UART2_TxCnt+=len; //UART1_TxCnt?????,?????UART1_TxBuff???????? UART2_DMA_TX_CH->CMAR = (u32)UART2_TX_BUF+len2;//???? UART2_DMA_TX_CH->CNDTR = UART2_DMA_TX_CH->CNDTR+len;//??DMA ?????? UART2_DMA_TX_CH->CCR |= UART2_DMA_TX_EN;//??DMA??1 while((usart2_tx_finish&UART2_FLAG)==0); return 1; } /*---------------------------------------------------------------------*/ /* INIT IO */ /* INPUT:NONE */ /* OUTPUT:NONE */ /*---------------------------------------------------------------------*/ void DMA1_Channel5_IRQHandler(void) { if(DMA_GetITStatus(UART2_DMA_TX_TC) == SET)//????????? { DMA2->IFCR = UART2_DMA_TX_TC; //?????? UART2_TxCnt=0;//?????? usart2_tx_finish |= UART2_FLAG; } } |
#define UART1_DMA_TX_IRQ DMA1_Channel4_IRQn
#define UART1_DMA_TX_EN DMA_CCR2_EN
#define UART1_DMA_TX_TC DMA1_IT_TC4
#define UART2_DMA_TX_CH DMA1_Channel5
#define UART2_DMA_TX_IRQ DMA1_Channel5_IRQn
#define UART2_DMA_TX_EN DMA_CCR2_EN
#define UART2_DMA_TX_TC DMA1_IT_TC5
改成通道6就可以了
评分
查看全部评分
评分
查看全部评分
多谢!