CH32V307,USART2使用DMA1_CH7发送完成后,DMA中断不能正常触发,不知道是那里有问题,求各位大神帮忙看看;谢谢!!

#include "debug.h"
#include "ch32v30x_gpio.h"
#include "ch32v30x_rcc.h"

/* Global typedef */

/* Global define */
#define TxBufferSize 24
#define RxBufferSize 24
/* Global Variable */
u8 TxBuffer[TxBufferSize]={
        0x0000, 0x0000, 0x0000, 0x0000,
        0x0001, 0x0001, 0x0001, 0x0001,
        0x0002, 0x0002, 0x0002, 0x0002,
        0x0003, 0x0003, 0x0003, 0x0003,
        0x0004, 0x0004, 0x0004, 0x0004,
        0x0005, 0x0005, 0x0005, 0x0005,
};
u8 RxBuffer[RxBufferSize];
u16 data[6];
/*********************************************************************
 * @fn      USARTx_CFG
 *
 * @brief   Initializes the USART2 & USART3 peripheral.
 *
 * @return  none
 */
void USART2_init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure = {0};
    USART_InitTypeDef USART_InitStructure = {0};
    USART_ClockInitTypeDef USART_ClockInitStruct={0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE );
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);

    /* USART2 TX-->A.2   RX-->A.3 CLK-->A.4*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
    USART_Init(USART2, &USART_InitStructure);

    USART_ClockInitStruct.USART_Clock = USART_Clock_Enable;
    USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
    USART_ClockInitStruct.USART_CPHA = USART_CPHA_1Edge;
    USART_ClockInitStruct.USART_LastBit = USART_LastBit_Enable;
    USART_ClockInit(USART2,&USART_ClockInitStruct);
}
//****************************************************
void DMAx_init(void)
{
    DMA_InitTypeDef DMA_InitStructure = {0};
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

    DMA_DeInit(DMA1_Channel7);
    DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART2->DATAR); /* USART2->DATAR:0x40004404 */
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&TxBuffer[0];
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure.DMA_BufferSize = TxBufferSize;
    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_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel7, &DMA_InitStructure);
    DMA_ClearFlag(DMA1_FLAG_TC7);
    DMA_ITConfig(DMA1_Channel7, DMA1_IT_TC7, ENABLE);
}
//*********************************************************************
void DMA1_Channel7_IRQHandler_Init(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;   //使能DMA1_Channel7中断通道
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //设置抢占优先级为0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;         //设置子优先级为0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;            //使能外部中断通道
    NVIC_Init(&NVIC_InitStructure);                            //中断优先级分组初始化
//  NVIC_EnableIRQ(DMA1_Channel7_IRQn);
}
//*********************************************************************
void ERAM_UsartDam_Init(void)//ERAM 存储器初始化
{
    USART2_init();
    USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
    USART_Cmd(USART2, ENABLE);
    DMAx_init();
    DMA1_Channel7_IRQHandler_Init();
    DMA_Cmd(DMA1_Channel7, ENABLE); /* USART2 Tx */
    NVIC_SetPendingIRQ(DMA1_Channel7_IRQn);//模拟接收到一帧数据,中断;
}
//*********************************************************************
void DMA1_Channel7_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
//********************************************************************
void DMA1_Channel7_IRQHandler(void)
{
    DMA_ClearITPendingBit(DMA1_Channel7_IRQn);/* Clear Flag */
    while(1);
}
/*********************************************************************
 */
int main(void)
{
    ERAM_UsartDam_Init();
    while(1)
        {
           while(DMA_GetCurrDataCounter(DMA1_Channel7)!=0)
               {
                   data[0] = DMA_GetCurrDataCounter(DMA1_Channel7);;
               }
        }

}


问题已解决,没有仔细看说明,给诸位填麻烦了!!中断没有使能。


只有登录才能回复,可以选择微信账号登录