STM32 DMA无法进入中断
发布网友
发布时间:2022-04-19 20:18
我来回答
共1个回答
热心网友
时间:2023-06-29 11:34
如果只是无法进中断,你检查下NVIC的中断映射是否配置,我用的是DMA发送,给你参考下。
相关定义:
#define USART1_Tx_DMA_Channel DMA1_Channel4
#define USART1_Tx_DMA_STREAM DMA2_Stream7
#define USART1_Tx_DMA_TCIF DMA1_FLAG_TC4
#define USART1_Rx_DMA_Channel DMA1_Channel5
#define USART1_Rx_DMA_FLAG DMA1_FLAG_TC5
#define USART1_DR_Base ((uint32_t)&USART1->DR)
代码:
#ifdef USART1_USE_DMA_MODE
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA1时钟
#ifdef USART1_DMA_TX
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;//设置中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//主优先级设置
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //设置优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//打开中断
NVIC_Init(&NVIC_InitStructure);
DMA_DeInit(USART1_Tx_DMA_Channel);
DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)m_UartDCB.pSendBuff;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
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_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(USART1_Tx_DMA_Channel, &DMA_InitStructure);//配置DMA1
DMA_ITConfig(USART1_Tx_DMA_Channel, DMA_IT_TC, ENABLE); //使能DMA发送中断
#endif//_USART_DMA_TX__
#endif//USE_DMA_MODE
追问你的设置我都有,找不到问题原题。但是我不能把代码贴进来。请问下你是怎么把代码贴进来的?
追答
贴代码很简单,下图中,
看到红色圈起来的地方没有,下拉展开,选C/C++就行了.