|
串口的配置 //复用口的打开 GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA | \ RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|\ RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO, ENABLE); //始终配置 RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|\ RCC_APB1Periph_UART4,ENABLE); //USART1 GPIO配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //USART2 GPIO配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //串口的配置 USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; 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_Rx | USART_Mode_Tx; //¶¨Òå½ÓÊպͷ¢ËÍʹÄÜ USART_Init(USART1, &USART_InitStructure); USART_Init(USART2, &USART_InitStructure); //中断的配置,注意在中断函数里面清除中断标志 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʹÄÜÖÐ¶Ï USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //ʹÄÜÖÐ¶Ï USART_ITConfig(UART4, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); //ʹÄÜÍâÉè USART_Cmd(USART2, ENABLE); //ʹÄÜ |
【源码】STLINK-V3MINI 高速USB仿真器,成功改刷【高速CMSIS-DAP】
STM32 USB CDC 虚拟多串口
STM32固件库分享,超全系列整理
实战经验 | 选择USBX模块生成USB CDC ACM无PD的项目
【MCU实战经验】基于STM32F103的二轮平衡车(6轴上位机 源代...
10张图带你完全掌握STM32 GPIO,从入门到精通,收藏就够了!
如果你解决了这些问题,就可以直接学STM32
STM32的分类和选型
学习STM32很简单?
STM32到底由什么组成?内核和外设的关系又是怎样的?看这篇!
微信公众号
手机版