基于STM32F103ZE的USART2 端口时钟.doc
《基于STM32F103ZE的USART2 端口时钟.doc》由会员分享,可在线阅读,更多相关《基于STM32F103ZE的USART2 端口时钟.doc(5页珍藏版)》请在三一文库上搜索。
1、基于STM32F103ZE的USART2 端口时钟USART1程序很多,看看USART2程序。注意红色部分,首先要使能相关端口的时钟。因为USART2可以映射成不同的端口,所以要端口映射。结合你自己的开发板,设置正确的映射口.(正点原子的是PA03PA02.)STM32F103ZE默认的USART2就是PA03PA02,如果配置映射,USART2端口是PD05PD06了。程序在正点原子开发板SRAM中调试通过,开发环境IAR5.30.void USART2_IniTIalise( u32 bound )GPIO_InitTypeDef GPIO_InitStructure;/I/O311NVI
2、C_InitTypeDef NVIC_InitStructure;/D311USART_InitTypeDef USART_InitStructure;/311 /* Enable the USART2 Pins Software Remapping */RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ,ENABLE);RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);/* Configure USART2 Rx (PA.03) as input floating */GPIO_InitStruc
3、ture.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA, GPIO_InitStructure);/* Configure USART2 Tx (PA.02) as alternate function push-pull */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mod
4、e = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, GPIO_InitStructure);/* Enable the USART2 Interrupt */NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_In
5、it(NVIC_InitStructure); USART_InitStructure.USART_BaudRate = bound; /a9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;/3a8yYUSART_InitStructure.USART_StopBits = USART_StopBits_1; /1USART_InitStructure.USART_Parity = USART_Parity_No; /TDUSART_InitStructure.USART_HardwareFlowControl =
6、USART_HardwareFlowControl_None;/YUSART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx;/ USART_Init(USART2, USART_InitStructure);USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);/USART_ITConfig(USART2, USART_IT_TXE, ENABLE);/* Enable USART2 */USART_Cmd(USART2, ENABLE);void USART2_IRQHandler(void
7、) if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) = SET) USART_SendData(USART2, USART_ReceiveData(USART2); 该程序功能是返回你发送到串口的数据。如果你的USART2接到PD端口上面了,要修改程序如下,这里就需要端口映射了,映射寄存器是AFIO控制的,它接在APB2时钟区域,所以下面的红色代码必须要有,蓝色代码对端口进行初始化。void USART2_Initialise( u32 bound )GPIO_InitTypeDef GPIO_InitStructure;/I/O311NVIC_
8、InitTypeDef NVIC_InitStructure;/D311USART_InitTypeDef USART_InitStructure;/311 /* Enable the USART2 Pins Software Remapping */RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD ,ENABLE);RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);GPIO_PinRemapCon
9、fig(GPIO_Remap_USART2, ENABLE); /* Configure USART2 Rx (PD.06) as input floating */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOD, GPIO_InitStructure);/* Configure USART2 Tx (PD.05) as alternate function push-pull */GPIO_InitStructure.G
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于STM32F103ZE的USART2 端口时钟 基于 STM32F103ZE USART2 端口 时钟
链接地址:https://www.31doc.com/p-3412066.html