OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 7798|回复: 2

STM32F4,UART3不能收发数据

[复制链接]

15

主题

99

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
366
金钱
366
注册时间
2012-5-23
在线时间
123 小时
发表于 2015-3-20 21:00:15 | 显示全部楼层 |阅读模式
5金钱
UART3不能收发数据,配置如下,硬件没问题
[mw_shl_code=c,true]void USART_Config(uint32_t BaudRate) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStruct; NVIC_InitTypeDef NVIC_InitStructure; //NVIC /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOC,GPIO_PinSource10, GPIO_AF_USART3); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_USART3); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOC, &GPIO_InitStructure); USART_InitStruct.USART_BaudRate = BaudRate; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_Parity = USART_Parity_No; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* USART configuration */ USART_Init(USART3,&USART_InitStruct); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable USART */ USART_Cmd(USART3, ENABLE); } //接收中断处理 void USART3_IRQHandler(void) { u8 res; //接收中断处理 if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) { // USART_ClearFlag(USART3, USART_IT_RXNE); res = USART3->DR; UartRec(res); } }[/mw_shl_code]


最佳答案

查看完整内容[请看2#楼]

解决了,配置没问题。串口线的问题。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

15

主题

99

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
366
金钱
366
注册时间
2012-5-23
在线时间
123 小时
 楼主| 发表于 2015-3-20 21:00:16 | 显示全部楼层
解决了,配置没问题。串口线的问题。
回复

使用道具 举报

15

主题

99

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
366
金钱
366
注册时间
2012-5-23
在线时间
123 小时
 楼主| 发表于 2015-3-20 21:26:02 | 显示全部楼层
自己顶一个,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-24 10:36

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表