STM32F207 DMA发送出错

2019-10-15 19:54发布

#define UART_RX_LEN     5
u8 Uart_Send_Buffer[UART_RX_LEN] ={0x12,0x34,0x56,0x78,0x90};

使用DMA发送串口数据,PC上面的串口调试助手显示为28 F6 00 20 31,今天刚入手学习DMA很多地方不懂,麻烦大神抽空看看DMA配置是否有问题,不胜感激,谢谢


void DMA_Configuration(void)
{
        DMA_InitTypeDef DMA_InitStructure;
        
        /* DMA clock enable */
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);//DMA2
        
        /* DMA1 Channel4 (triggered by USART1 Tx event) Config */ //DMA2 Stream 7 Channel 4
        DMA_DeInit(DMA2_Stream7);
        DMA_InitStructure.DMA_Channel = DMA_Channel_4;
        DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART1->DR);
        DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Uart_Send_Buffer;
        DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
        DMA_InitStructure.DMA_BufferSize = 5;  
        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_High;
        
        DMA_Init(DMA2_Stream7, &DMA_InitStructure);
        DMA_ITConfig(DMA2_Stream7, DMA_IT_TC, ENABLE);
        DMA_ITConfig(DMA2_Stream7, DMA_IT_TE, ENABLE);
        
        /* Enable USART1 DMA TX request */
        USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
        DMA_ClearFlag(DMA2_Stream7, DMA_FLAG_TCIF7);  
        DMA_Cmd(DMA2_Stream7, DISABLE);        
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
zhcy周
1楼-- · 2019-10-15 23:52
呼叫原子哥,管用嘛
zhcy周
2楼-- · 2019-10-16 02:56
 精彩回答 2  元偷偷看……
zhcy周
3楼-- · 2019-10-16 04:58
中断配置
void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
       
        /* Configure one bit for preemption priority */
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
       
        /* Enable the USART1 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream7_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
       

}

正点原子
4楼-- · 2019-10-16 06:35
怀疑你的波特率有问题。先不用DMA,你直接发送一个字符试试看先
zhcy周
5楼-- · 2019-10-16 10:25
正点原子 发表于 2017-1-2 14:56
怀疑你的波特率有问题。先不用DMA,你直接发送一个字符试试看先

问题解决了~DMA配置的有问题~谢谢原子哥~

一周热门 更多>