我用的是原子F407开发板,我的DMA双缓存配置如下
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
if((u32)DMA_Streamx>(u32)DMA2)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
}else
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);
}
DMA_DeInit(DMA_Streamx);
while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){}
DMA_InitStructure.DMA_Channel = chx;
DMA_InitStructure.DMA_PeripheralBaseAddr = par;
DMA_InitStructure.DMA_Memory0BaseAddr = mar0;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = ndtr;
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_Medium;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA_Streamx, &DMA_InitStructure);
/*DMA double buffer mode*///
DMA_DoubleBufferModeConfig(DMA_Streamx,(uint32_t)&mar1,DMA_Memory_0);
DMA_DoubleBufferModeCmd(DMA_Streamx,ENABLE);
发送的双缓存为和发送的数据数量为
#define SEND_BUF_SIZE 8
u8 SendBuff[]={0x01,0x02,0x03,0x04};
u8 SendBuff1[]={0x09,0x0a,0x0b,0x0c};
我在主函数中
while(1)
{
if(DMA_GetFlagStatus(DMA2_Stream7,DMA_FLAG_TCIF7)!=RESET)
{
DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7);
break;
}
}
现象:
1:当我使能DMA传输时
MYDMA_Enable(DMA2_Stream7,SEND_BUF_SIZE);
串口不停的循环收到
01 02 03 04 09 0A 0B 0C 10 00 00 00 08 00 00 00
应该只收到01 02 03 04 09 0A 0B 0C才对呀
为什么会有10 00 00 00 08 00 00 00这些数据呀?
2:当我在传输完成时关掉DMA也就是只传一次的时候
if(DMA_GetFlagStatus(DMA2_Stream7,DMA_FLAG_TCIF7)!=RESET)
{
MYDMA_Disable(DMA2_Stream7);
DMA_ClearFlag(DMA2_Stream7,DMA_FLAG_TCIF7);
break;
}
数据是正确的,即01 02 03 04 09 0A 0B 0C没有乱码。
求助:拜托各位大神指点下,怎么循环发送,没有乱码。谢谢啦!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>