STM32F4库函数初始化系列:串口DMA接收

 1 u8 _data1[4];
 2 void Configuration(void)
 3 {
 4   USART_InitTypeDef USART_InitStructure;
 5   DMA_InitTypeDef DMA_InitStructure; 
 6   GPIO_InitTypeDef GPIO_InitStructure;
 7   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
 8    //TX
 9   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; 
10   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
11   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
12   GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
13   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
14   GPIO_Init(GPIOB, &GPIO_InitStructure);
15   //RX
16   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; 
17   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
18   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
19   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
20   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
21   GPIO_Init(GPIOB, &GPIO_InitStructure);
22   
23   GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
24   GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
25   
26   DMA_InitStructure.DMA_Channel = DMA_Channel_4;  
27   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
28   DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)_data1;
29   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
30   DMA_InitStructure.DMA_BufferSize = 4;
31   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
32   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
33   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
34   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
35   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
36   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
37   DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         
38   DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
39   DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
40   DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
41   DMA_Init(DMA1_Stream1, &DMA_InitStructure);
42   DMA_Cmd(DMA1_Stream1, ENABLE);
43   
44   USART_OverSampling8Cmd(USART3, ENABLE);  
45   USART_InitStructure.USART_BaudRate = 38400;
46   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
47   USART_InitStructure.USART_StopBits = USART_StopBits_1;
48   USART_InitStructure.USART_Parity = USART_Parity_No;
49   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
50   USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
51   USART_Init(USART3, &USART_InitStructure);
52   USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
53   DMA_Cmd(DMA1_Stream1, ENABLE); 
54   USART_Cmd(USART3, ENABLE); 
55 }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值