STM32F4库函数初始化系列:DMA串口接收
1 void _UART2_Configuration(void) 2 { 3 USART_InitTypeDef USART_InitStructure; 4 5 USART_OverSampling8Cmd(USART2, ENABLE); 6 USART_InitStructure.USART_BaudRate = 19200; 7 USART_InitStructure.USART_WordLength = USART_WordLength_8b; 8 USART_InitStructure.USART_StopBits = USART_StopBits_1; 9 USART_InitStructure.USART_Parity = USART_Parity_No; 10 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 11 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 12 USART_Init(USART2, &USART_InitStructure); 13 14 USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE); 15 16 DMA_Cmd(DMA1_Stream5, ENABLE); 17 18 USART_Cmd(USART2, ENABLE); 19 } 20 21 void _DMA_Configuration(void) 22 { 23 DMA_InitTypeDef DMA_InitStructure; 24 DMA_InitStructure.DMA_Channel = DMA_Channel_4; 25 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(USART2->DR); 26 DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)_Compass_Value; 27 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; 28 DMA_InitStructure.DMA_BufferSize = 3; 29 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 30 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 31 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; 32 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; 33 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 34 DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; 35 DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; 36 DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; 37 DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; 38 DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; 39 DMA_Init(DMA1_Stream5, &DMA_InitStructure); 40 41 /* DMA2_Stream0 enable */ 42 DMA_Cmd(DMA1_Stream5, ENABLE); 43 }