本帖最后由 taly_yang 于 2014-1-18 12:12 编辑
请大虾帮忙看看,问题出在哪,谢谢
1,MCU是STM32F107
2,UART4发送完了一帧数据后,不能进入DMA2中断程序,但是中断请求标志有置起(TCIF5)
3,调试时观察各个相关配置的标志位都有置起(DMA2--->TCIE, EN ;UART4--->TE ,DMAT ;)
4,全局中断都有打开(相关标志位也有被置起 SETENA59 ,CLREN59,)
和 网上一个兄弟同样的问题,但是没看到相关的解决办法。
下面是配置代码:
/******************************************************
*******************************************************/
void Uart4Init(void){//
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);//使能DMA时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4 , ENABLE); //使能串口时钟
// *****************************************
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel4_5_IRQn;//; DMA2_Channel5_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PriorityGroup_4;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* UART4 configured as follow:*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_2;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;//USART_Mode_Tx|USART_Mode_Rx;
USART_ClockInitStruct.USART_Clock = USART_Clock_Disable;
USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStruct.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable;
USART_Init(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
//--------
USART_DMACmd(UART4,USART_DMAReq_Tx,ENABLE);
//-----------------
/* DMA channel1 configuration ----------------------------------------------*/
//DMA_DeInit(DMA2_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&UART4->DR); //外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&artnet_dmxUniverse[send_buffer[3]-1];//内存地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//DMA_DIR_PeripheralSRC;//DMA 传输方向
DMA_InitStructure.DMA_BufferSize = 100;
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_Mode_Circular; :设置DMA的传输模式:连续不断的循环模式. DMA_Mode_Normal:这里是普通模式,即传输完成后就关闭了DMA
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel5, &DMA_InitStructure);
DMA_ITConfig(DMA2_Channel5, DMA_IT_TC, ENABLE); //使能DMA 中断
USART_Cmd(UART4, ENABLE); // Enable USART1
DMA_Cmd(DMA2_Channel5, ENABLE); //使能通道1
}
/******************************************************
*******************************************************/
void DMA2_Channel4_5_IRQHandler(void)
{
/* Test on DMA Channel1 Transfer Complete interrupt */
if(DMA_GetITStatus(DMA2_IT_TC5))
{
DMA_ClearITPendingBit(DMA2_IT_GL5);
USART_DMACmd(UART4,USART_DMAReq_Tx,DISABLE);
USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
DMA_ITConfig(DMA2_Channel5, DMA_IT_TC, DISABLE); //
DMA_Cmd(DMA2_Channel5, DISABLE); //
TxState = STOPED;
}
|