在F407 DMA的double Buffer mode上卡了好久了!大家看看我的配置哪里出问题了?
先附上代码
uint8_t Buffer0[]
= {0x11,0x22,0x33,0x44}; //无符号的8位整型数
uint8_t Buffer1[] =
{0x55,0x66,0x77,0x88}; //无符号的8位整型数
void
USART3_DMA1_Configuration(void)
{
DMA_InitTypeDef
DMA_InitStructure;
/*首先开 DMA2时钟,由407参考手册-RM0090-Reference manual
165页可知,UASRT6与 DMA2映射,而且 DMA2挂载在 AHB1时钟总线上*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1|RCC_AHB1Periph_DMA2,
ENABLE);
/*由 RM0090-Reference manual 第165页映射表可知,USART3映射在
Channel_5的 Stream6和 Stream7上,在这里可以选择 Stream6 */
DMA_DeInit(DMA1_Stream3);
DMA_StructInit( &DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //选择 Channel_5
DMA_InitStructure.DMA_PeripheralBaseAddr = USART3_DR_Addr;
//数据传输的外设首地址,详解见上
DMA_InitStructure.DMA_Memory0BaseAddr =
(uint32_t)Buffer0; //自己定义待发送数组的首地址,要强制转换为32位
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
//数据传输方向选择为内存->外设
DMA_InitStructure.DMA_BufferSize = 8;
//传输数据大小为8,大小要配合定义的数组类型和外设数据类型,否则会丢失或补充数据
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//外设地址寄存器自动增加禁止,因为这里只用到了 DR 数据寄存器
DMA_InitStructure.DMA_MemoryInc =
DMA_MemoryInc_Enable; //内存地址自增允许,因为要读取一个数组
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
//外设的数据大小,因为 USART3_DR 数据寄存器为8位,故选Byte
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //这里也选 Byte
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //DMA 传输模式为
DMA_Mode_Normal,如果为 DMA_Mode_Circular,将会循环传输
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //优先级为 High
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_DoubleBufferModeConfig(DMA1_Stream3, (uint32_t)Buffer1,
DMA_Memory_1);
DMA_DoubleBufferModeCmd(DMA1_Stream3, ENABLE);
DMA_Init(DMA1_Stream3, &DMA_InitStructure);
DMA_Cmd(DMA1_Stream3, DISABLE); //使能 DMA1_Stream3通道
/*DMA 中断开*/
DMA_ClearITPendingBit(DMA1_Stream3, DMA_IT_TCIF3);
DMA_ITConfig(DMA1_Stream3, DMA_IT_TC,
ENABLE);
}
我在DMA_Init前加了这么两句话,
DMA_DoubleBufferModeConfig(DMA1_Stream3, (uint32_t)Buffer1, DMA_Memory_1);
DMA_DoubleBufferModeCmd(DMA1_Stream3,
ENABLE);
如果改成DMA_Memory_0的话,就会正常的打印出11 22 33 44 55 66 77
88
但是改成DMA_Memory_1的话,现象就不对了!55 66 77 88 15 00 08 52
请大家看看
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
呵呵~是的!我后来也明白了!谢谢!
直击重点啊!
一周热门 更多>