1、nitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( . . / USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);/开启中断 USART_ITConfig(USART2,
2、USART_IT_IDLE , ENABLE); /开启空中断 USART_Cmd(USART2, ENABLE); /使能串口 / 串口 3 初始化函数 void uart3_init(u32 bound) /GPIO端口置 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); / 使能 GPIOB RCC_APB1
3、PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); / 使能 USART3 USART_DeInit(USART3); /复位串口 3 /USART1_TX PB.10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; /PB.10 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /复用推挽出 GPIO_Init(GPIOB, /初始化 PB.11 /USART1_RX P
4、B.11 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;/浮空入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, /初始化 PB /USART 初始化置 /#ifdef EN_USART3_RX / 如果使能了接收 USART_InitStructure.USART_BaudRate = bound;/一般置9600; USART_InitStructure.USA
5、RT_WordLength = USART_WordLength_8b;/ 字 8 位 数据格式 USART_InitStructure.USART_StopBits = USART_StopBits_1;/一个停止位 USART_InitStructure.USART_Parity = USART_Parity_No;/无奇偶校位 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;/无硬件数据流控制 USART_InitStructure.USART_Mode = USART_Mode
6、_Rx | USART_Mode_Tx; /收 模式 USART_Init(USART3, /初始化串口 /Usart1 NVIC 配置 . . NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;/占先 3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; / 子先 3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /IRQ 通道使能
7、NVIC_Init( / 根据指定的参数初始化VIC 寄存器 / /*Enable DMA Channel2 Interrupt */ / NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( /*Ena
8、ble DMA Channel3 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( / USART_ITConfig(USART3, USART_IT_RXNE, ENABL
9、E);/开启中断 USART_ITConfig(USART3, USART_IT_IDLE , ENABLE); /开启空中断 USART_Cmd(USART3, ENABLE); /使能串口 / 串口 4 初始化函数 void uart4_init(u32 bound) GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; /定DMA初始化构体 DMA_
10、InitStructure / NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); / NVIC先分 0 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); / 打开串口外的 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); . .
11、/ 串口 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_Init(GPIOC, /初始化串口 1 出 IO 口 / 定 UART4 Rx (PC.11) 空入 GPIO_InitStructure.GPIO_Pin =
12、GPIO_Pin_11; /IO口的第 3 脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;/IO口空入 GPIO_Init(GPIOC, /初始化串口1 入 IO 口 / 串口 4 参数初始化定部分, 串口 1 参数 9600 , 8 ,1 ,N 接收中断方式 USART_InitStructure.USART_BaudRate = bound; / 定速率 USART_InitStructure.USART_WordLength = USART_WordLength_8b; / 定数据位 数 USART_InitStructure.USART_StopBits = USART_StopBits_1; / 定停止位个数 USART_InitStructure.USART_Parity = USART_Parity_No ; /不用校位 USART_InitStructure.USA