stm32
f407 串口1 用DMA发送 发送400个数据 ,经常有数据没有发送完成
串口DMA配置函数
void Usart1_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
DMA_DeInit(DMA2_Stream7);
while (DMA_GetCmdStatus(DMA2_Stream7) != DISABLE){}
DMA_InitStructure.DMA_Channel =DMA_Channel_4;
DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base;
DMA_InitStructure.DMA_Memory0BaseAddr =(u32)SendBuff;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
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_Medium;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream7, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream7, DISABLE);
DMA_ITConfig(DMA2_Stream7,DMA_IT_TC,ENABLE);
}
main函数调用函数
void USART1_DMA4_SendData(uint16_t CharLength)
{
while (Flag_Uart_Send){;}
Flag_Uart_Send = 1;
DMA_Cmd(DMA2_Stream7,DISABLE);
while (DMA_GetCmdStatus(DMA2_Stream7) != DISABLE){}
DMA_SetCurrDataCounter(DMA2_Stream7,CharLength);
DMA_Cmd(DMA2_Stream7,ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
}
DMA传输完成中断函数
void DMA2_Stream7_IRQHandler(void)
{
DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7);
DMA_Cmd(DMA2_Stream7,DISABLE);
Flag_Uart_Send = 0;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
已经正常,跟此段程序无关
一周热门 更多>