有谁用过DMA的双缓冲区模式吗?请教一下应该怎么配置,也帮我看看以下问题! 1.当我还没有配置双缓冲模式的时候,也就是没有DMA_DoubleBufferModeConfig()和DMA_DoubleBufferModeCmd()这两句的时候,Buffer1和Buffer2的内容就已经在循环发送到串口,然而我并没有让他发送Buffer2的内容,配置如下,这一点我不明白。结果如图一。 å¾ä¸ 2.当我按自己的理解添加了 DMA_DoubleBufferModeConfig(DMA2_Stream7,(uint32_t)Buffer2,DMA_Memory_0); DMA_DoubleBufferModeCmd(DMA2_Stream7,ENABLE);之后,我观察发送的数据发现,在发送了Buffer1和Buffer2的数据之后,又发送了同样数量的00,为什么会有这些00,这里我也不太明白。结果如图二。 void USART_DMA_Config(void) { DMA_InitTypeDef DMA_InitStructure; /* DMA2_Stream7 channel4 configuration ---------------------------------------------*/ DMA_DeInit(DMA2_Stream7); DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Address; DMA_InitStructure.DMA_Channel = DMA_Channel_4; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Buffer1; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_BufferSize = 80; 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_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //DMA_DoubleBufferModeConfig(DMA2_Stream7,(uint32_t)Buffer2,DMA_Memory_0); //DMA_DoubleBufferModeCmd(DMA2_Stream7,ENABLE); DMA_Init(DMA2_Stream7, &DMA_InitStructure); DMA_Cmd(DMA2_Stream7, ENABLE); } 另附上 const uint16_t Buffer1[20] = { 0x1234, 0x5678, 0x1ABC, 0xDEF0, 0x5555, 0x1748, 0x9027, 0x4424, 0x9623, 0x0932, 0x9744, 0x7845, 0x0912, 0x1111, 0x1772, 0x9736, 0x0933, 0x0187, 0x9567, 0x9977 }; const uint16_t Buffer2[20] = { 0x1111, 0x7845, 0x0912, 0xDEF0, 0x9977, 0x0187, 0x9736, 0x9567, 0xDEF0, 0x1772, 0x5555, 0x1111, 0x0933, 0x1234, 0x9567, 0x9736, 0x4444, 0x9ABC, 0x1111, 0x4424 }; |
02、传输的方式是字节流(byte)方向从内存到外设,所以buffer1和buffer2的实际内存大小各为20*2 = 40 bytes ,DMA设置传输长度是80,模式是 DMA_Mode_Circular 。这个现象是 每次传送都是80个字节长度且循环往复的发送。这就导致现象2发生 。如果传入的是buffer2的地址而其内容就40个字节大小,那结果你晓得。
感谢你的回答,我现在是明白了,现在仔细想想还我自己理解不到位导致的,忽视了一些细节