STM32F103多個串口配置DMA程序(純代碼版詳解)_第1頁
STM32F103多個串口配置DMA程序(純代碼版詳解)_第2頁
STM32F103多個串口配置DMA程序(純代碼版詳解)_第3頁
STM32F103多個串口配置DMA程序(純代碼版詳解)_第4頁
STM32F103多個串口配置DMA程序(純代碼版詳解)_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、軟件:KeilMDK芯片:STM32F103/STM32F107串口數(shù)量:4備注:4個串口均配置為DMA讀取/串口1初始化函數(shù)void uart1_init(u32 bound) /GPIO端口設置GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);/使能USART1,GPIOA時

2、鐘USART_DeInit(USART1); /復位串口1/USART1_TX PA.9GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; /PA.9GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;/復用推挽輸出GPIO_Init(GPIOA, &GPIO_InitStructure); /初始化PA9/USART1_RX PA.10GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GP

3、IO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;/浮空輸入GPIO_Init(GPIOA, &GPIO_InitStructure); /初始化PA10/Usart1 NVIC 配置NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;/搶占優(yōu)先級3NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;/子優(yōu)先級3NVIC_InitStruc

4、ture.NVIC_IRQChannelCmd = ENABLE;/IRQ通道使能NVIC_Init(&NVIC_InitStructure);/根據(jù)指定的參數(shù)初始化VIC寄存器/*Enable DMA Channel4 Interrupt */NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStruc

5、ture.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);/*Enable DMA Channel5 Interrupt */NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd =

6、 ENABLE;NVIC_Init(&NVIC_InitStructure);/USART 參數(shù)初始化設置USART_InitStructure.USART_BaudRate = bound;/一般設置為9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;/字長為8位數(shù)據(jù)格式USART_InitStructure.USART_StopBits = USART_StopBits_1;/一個停止位USART_InitStructure.USART_Parity = USART_Parity_No;/無奇偶校驗位USART_

7、InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;/無硬件數(shù)據(jù)流控制USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;/收發(fā)模式USART_Init(USART1, &USART_InitStructure); /初始化串口/ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);/開啟中斷USART_ITConfig(USART1, USART_IT_IDLE , ENABLE);/開

8、啟空閑中斷USART_Cmd(USART1, ENABLE); /使能串口 /串口2初始化函數(shù)void uart2_init(u32 bound)GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);/使能GPIOA時鐘RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);/

9、使能USART2時鐘GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;/PA2GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;/復用推挽GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;/PA3GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; /浮空輸入GP

10、IO_Init(GPIOA, &GPIO_InitStructure); RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,ENABLE);/復位串口2RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,DISABLE);/停止復位USART_InitStructure.USART_BaudRate = bound;/一般設置為9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;/8位數(shù)據(jù)長度USART_InitStructure.USART

11、_StopBits = USART_StopBits_1;/一個停止位USART_InitStructure.USART_Parity = USART_Parity_No;/奇偶校驗位USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;/無硬件數(shù)據(jù)流控制USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;/收發(fā)模式USART_Init(USART2, &USART_InitStructure); ; /初始化串口NV

12、IC_InitStructure.NVIC_IRQChannel = USART2_IRQn; /使能串口2中斷NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; /先占優(yōu)先級2級NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /從優(yōu)先級2級NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /使能外部中斷通道NVIC_Init(&NVIC_InitStructure); /根據(jù)NVIC_InitStruct中指定的參數(shù)初始化外設NV

13、IC寄存器/Enable DMA Channel7 Interrupt /NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);/*Enable DMA Channel6

14、Interrupt */NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);/ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE)

15、;/開啟中斷USART_ITConfig(USART2, USART_IT_IDLE , ENABLE);/開啟空閑中斷USART_Cmd(USART2, ENABLE); /使能串口 /串口3初始化函數(shù)void uart3_init(u32 bound) /GPIO端口設置GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE)

16、;/使能GPIOB時鐘RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);/使能USART3時鐘USART_DeInit(USART3); /復位串口3/USART1_TX PB.10GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; /PB.10GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;/復用推挽輸出GPIO_Init(GPIOB, &GPIO_InitSt

17、ructure); /初始化PB.11/USART1_RX PB.11GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;/浮空輸入GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure); /初始化PB/USART 初始化設置/#ifdef EN_USART3_RX /如果使能了接收USART_InitStructure.USART_Baud

18、Rate = bound;/一般設置為9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;/字長為8位數(shù)據(jù)格式USART_InitStructure.USART_StopBits = USART_StopBits_1;/一個停止位USART_InitStructure.USART_Parity = USART_Parity_No;/無奇偶校驗位USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;/無硬件數(shù)據(jù)流控制U

19、SART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;/收發(fā)模式USART_Init(USART3, &USART_InitStructure); /初始化串口/Usart1 NVIC 配置NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;/搶占優(yōu)先級3NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;/子優(yōu)先級3NVI

20、C_InitStructure.NVIC_IRQChannelCmd = ENABLE;/IRQ通道使能NVIC_Init(&NVIC_InitStructure);/根據(jù)指定的參數(shù)初始化VIC寄存器/ /*Enable DMA Channel2 Interrupt */ /NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1

21、;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);/*Enable DMA Channel3 Interrupt */NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel3_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_

22、IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);/ USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);/開啟中斷USART_ITConfig(USART3, USART_IT_IDLE , ENABLE);/開啟空閑中斷USART_Cmd(USART3, ENABLE); /使能串口 /串口4初始化函數(shù)void uart4_init(u32 bound)GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStruct

23、ure;NVIC_InitTypeDef NVIC_InitStructure;DMA_InitTypeDef DMA_InitStructure; /定義DMA初始化結(jié)構(gòu)體DMA_InitStructure /NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /選擇NVIC優(yōu)先級分組0 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); RCC_APB2PeriphClockCmd(RCC_A

24、PB2Periph_GPIOC,ENABLE);/ 打開串口外設的時鐘RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);/串口4所使用管腳輸出輸入定義/定義UART4 Tx (PC.10)腳為復用推挽輸出GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; /IO口的第2腳GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /IO口速度GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /IO口復用推挽輸出GPIO_

25、Init(GPIOC, &GPIO_InitStructure); /初始化串口1輸出IO口/定義 UART4 Rx (PC.11)為懸空輸入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; /IO口的第3腳GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;/IO口懸空輸入GPIO_Init(GPIOC, &GPIO_InitStructure); /初始化串口1輸入IO口 /串口4參數(shù)初始化定義部分,串口1參數(shù)為9600 , 8 ,1 ,N 接收中斷方式 USART_InitStructure.US

26、ART_BaudRate = bound; /設定傳輸速率USART_InitStructure.USART_WordLength = USART_WordLength_8b; /設定傳輸數(shù)據(jù)位數(shù)USART_InitStructure.USART_StopBits = USART_StopBits_1; /設定停止位個數(shù)USART_InitStructure.USART_Parity = USART_Parity_No ; /不用校驗位USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;/

27、不用流量控制USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /使用接收和發(fā)送功能USART_Init(UART4, &USART_InitStructure); /初始化串口4USART_ITConfig(UART4, USART_IT_IDLE,ENABLE); /使能串口4接收中斷USART_Cmd(UART4, ENABLE); /使能串口4USART_ClearFlag(UART4, USART_FLAG_TC); / 清標志(后增加) DMA_DeInit(DMA2_Channel3); /重置DMA 2

28、通道配置DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004C04; /外設地址 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)USART4_RECEIVE_DATA; /內(nèi)存地址 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; /外設作為數(shù)據(jù)目的地 DMA_InitStructure.DMA_BufferSize = 512; /DMA緩存大小:BufferSize DMA_InitStructure.DMA_PeripheralInc = DMA_

29、PeripheralInc_Disable; /外設地址寄存器不遞增 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; /內(nèi)存地址寄存器遞增DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; /外設數(shù)據(jù)寬度為8位 DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte; /內(nèi)存數(shù)據(jù)寬度為8位 DMA_InitStructure.DMA_Mode = DMA_Mode

30、_Circular; /工作在正常緩存模式 DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; /設置DMA通道優(yōu)先級為高 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; /禁止DMA通道設置為內(nèi)存至內(nèi)存?zhèn)鬏?DMA_Init(DMA2_Channel3, &DMA_InitStructure); /初始化 DMA_ITConfig(DMA2_Channel3, DMA_IT_TC, ENABLE);DMA_ITConfig(DMA2_Channel3, DMA_IT_TE, ENABLE);

31、 USART_DMACmd(UART4, USART_DMAReq_Rx, ENABLE);DMA_Cmd(DMA2_Channel3, ENABLE);/使能串口4中斷NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NV

32、IC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);USART_Cmd(UART4, ENABLE);/DMA的配置void

33、 DMA_Configuration(void) DMA_InitTypeDef DMA_InitStructure; /* DMA clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);/DMA1/串口1 dma配置/ /* DMA1 Channel4 (串口1 TX) Config */ DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr = 0x; DMA_InitStructure.DMA_MemoryBaseAddr = (

34、uint32_t)USART1_SEND_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralData

35、Size_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; /DMA工作模式DMA_Mode_Circular DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel4, &DMA_InitStructu

36、re); DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, ENABLE); DMA_ITConfig(DMA1_Channel4, DMA_IT_TE, ENABLE); /* Enable USART1 DMA TX request */ USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE); DMA_Cmd(DMA1_Channel4, DISABLE); /使能 /* DMA1 Channel5 (串口1 RX) Config */ DMA_DeInit(DMA1_Channel5); DMA_InitStructure

37、.DMA_PeripheralBaseAddr = 0x; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART1_RECEIVE_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_Memory

38、Inc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; /DMA工作模式DMA_Mode_Circular DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitSt

39、ructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel5, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE); DMA_ITConfig(DMA1_Channel5, DMA_IT_TE, ENABLE); /* Enable USART1 DMA RX request */ USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE); DMA_Cmd(DMA1_Channel5, ENABLE); /使能/串口2 dm

40、a配置/ /* DMA1 Channel7 (串口2 TX) Config */ DMA_DeInit(DMA1_Channel7); DMA_InitStructure.DMA_PeripheralBaseAddr = 0x; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_SEND_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_Perip

41、heralInc = 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_Normal; /DMA工作模式 DMA_Mode_Circul

42、ar DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel7, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE); DMA_ITConfig(DMA1_Channel7, DMA_IT_TE, ENABLE); /* Enable USART1 DMA TX request */ USART_DM

43、ACmd(USART2, USART_DMAReq_Tx, ENABLE); DMA_Cmd(DMA1_Channel7, DISABLE); /使能 /* DMA1 Channel6 (串口2 RX) Config */ DMA_DeInit(DMA1_Channel6); DMA_InitStructure.DMA_PeripheralBaseAddr = 0x; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_RECEIVE_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_Peripher

44、alSRC; DMA_InitStructure.DMA_BufferSize = 512; 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_By

45、te; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; /DMA工作模式DMA_Mode_Circular DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel6, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE); DMA_ITConfig(D

46、MA1_Channel6, DMA_IT_TE, ENABLE); /* Enable USART2 DMA RX request */ USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE); DMA_Cmd(DMA1_Channel6, ENABLE); /使能/串口3 dma配置/ /* DMA1 Channel2 (串口3 TX) Config */ DMA_DeInit(DMA1_Channel2); DMA_InitStructure.DMA_PeripheralBaseAddr =0x; DMA_InitStructure.DMA_Memory

47、BaseAddr = (uint32_t)USART3_SEND_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_Pe

48、ripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; /DMA工作模式 DMA_Mode_Circular DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel2, &DM

49、A_InitStructure); DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE); DMA_ITConfig(DMA1_Channel2, DMA_IT_TE, ENABLE); /* Enable USART1 DMA TX request */ USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE); DMA_Cmd(DMA1_Channel2, DISABLE); /使能 /* DMA1 Channel3 (串口3 RX) Config */ DMA_DeInit(DMA1_Channel3); DMA_

50、InitStructure.DMA_PeripheralBaseAddr = 0x; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART3_RECEIVE_DATA; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc

51、 = 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工作模式DMA_Mode_Circular DMA_Mode_Normal DMA_InitStructure.DMA_Priority = DMA_Priority_Med

52、ium; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel3, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE); DMA_ITConfig(DMA1_Channel3, DMA_IT_TE, ENABLE); /* Enable USART2 DMA RX request */ USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE); DMA_Cmd(DMA1_Channel3, ENABLE); /使能/使用DMA發(fā)數(shù)據(jù)中斷服務程序/void DMA1_Channel4_IRQHandler(void) DMA_ClearITPendingBit(DMA1_IT_TC4); DMA_ClearITPendingBit(DMA1_IT_TE4); DMA_Cmd(DMA1_Channel4, DISABLE);/關閉DMA USART1_TX_Fin

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論