你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。
chrome
firefox
safari
ie8及以上
ST
意法半导体官网
STM32
中文官网
ST
全球论坛
登录/注册
首页
技术问答
话题
资源
创客秀
视频
标签
每日签到
STM32团队2
论坛吐槽优化专区
升级测试
哪位大侠用过F103ZE的UART4或者5啊,总是调不通
[复制链接]
nuqililove
提问时间:2014-4-13 17:28 /
阅读主题, 点击返回1楼
赞
0
收藏
0
评论
16
分享
发布时间:2014-4-13 17:28
请先
登录
后回复
16个回答
nuqililove
回答时间:2014-4-17 21:41:33
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
?
赞
0
评论
回复
支持
反对
对上帝说不
回答时间:2014-4-18 08:56:19
a0a.1 0b0c
回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
还没有调通吗?反正我用F103RC串口1~5是全通的
赞
0
评论
回复
支持
反对
dlyt03
回答时间:2014-4-18 09:45:48
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
换个例程调试看看
赞
0
评论
回复
支持
反对
zergl
回答时间:2014-4-18 10:35:57
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
这是我目前使用的,5个口都用到,请参考.
/****************************************
* ÎļþÃû £ºusart.c
| PA9 - USART1(Tx) |
| PA10 - USART1(Rx) |
| PA2 - USART2(Tx) |
| PA3 - USART2(Rx) |
| PB10 - USART3(Tx) |
| PB11 - USART3(Rx) |
| PC10 - USART4(Tx) |
| PC11 - USART4(Rx) |
| PC12 - USART5(Tx) |
| PD2 - USART5(Rx) |
**********************************************************************************/
#include "usart.h"
#include "plc.h"
#include
#include
USART_InitTypeDef USART_InitStructure;
void GPIO_Tx_Usart1_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Tx_Usart2_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Tx_Usart3_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART4 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void GPIO_Tx_Usart4_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART4 Tx (PC.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void GPIO_Tx_Usart5_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART5 Tx (PC.12) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void USART_Config(void)
{
/* USART mode config */
USART_InitStructure.USART_BaudRate = 250000; //ÅäÖÃUSART1µÄ²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //USART½ÓÊÕ»òÕß´«Êä8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //USART·¢Ë͵ÄֹͣλΪ1λ
USART_InitStructure.USART_Parity = USART_Parity_No ; //¶¨ÒåUSARTµÄÆæÅ¼Ð£ÑéλΪÎÞ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //¶¨ÒåUSARTµÄÓ²¼þÁ÷¿ØÄ£Ê½µÄRTSºÍCTSʹÄÜ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ʹÄÜ·¢ËͺͽÓÊÕģʽ
}
/*
* º¯ÊýÃû£ºUART_NVIC_Configuration
* ÃèÊö £ºUARTÖжÏÓÅÏȼ¶ÅäÖÃ
*/
void Uart_NVIC_Configuration(USART_TypeDef* USARTx)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //ÉèÖÃÓÅÏȼ¶·Ö×é
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÇÀÕ¼ÓÅÏȼ¶Îª×î¸ß0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //ÏìÓ¦ÓÅÏȼ¶Îª×î¸ß0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ͨµÀʹÄÜ
switch (*(uint32_t*)&USARTx)
{
case USART1_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case USART2_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case USART3_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case UART4_BASE:
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case UART5_BASE:
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
default:
break;
}
}
/*
* º¯ÊýÃû£ºUSART1_Config
* ÃèÊö £ºUSART1 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA9 - USART1(Tx) |
| PA10 - USART1(Rx) |
*/
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_Tx_Usart1_Config(GPIO_Mode_AF_PP);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_Config();
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
Uart_NVIC_Configuration(USART1);
}
/*
* º¯ÊýÃû£ºUSART2_Config
* ÃèÊö £ºUSART2 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA2 - USART2(Tx) |
| PA3 - USART2(Rx) |
*/
void USART2_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART2 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_Tx_Usart2_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PA.03) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_Config();
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
Uart_NVIC_Configuration(USART2);
}
/*
* º¯ÊýÃû£ºUSART3_Config
* ÃèÊö £ºUSART3 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PB10 - USART3(Tx) |
| PB11 - USART3(Rx) |
*/
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART3 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* Configure USART2 Tx (PB.10) as alternate function push-pull */
GPIO_Tx_Usart3_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_Config();
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
Uart_NVIC_Configuration(USART3);
}
/*
* º¯ÊýÃû£ºUSART4_Config
* ÃèÊö £ºUSART4 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PC10 - USART4(Tx) |
| PC11 - USART4(Rx) |
*/
void USART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART4 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
/* Configure USART4 Tx (PC.10) as alternate function push-pull */
GPIO_Tx_Usart4_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PC.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_Config();
USART_Init(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
Uart_NVIC_Configuration(UART4);
}
/*
* º¯ÊýÃû£ºUSART5_Config
* ÃèÊö £ºUSART5 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PC12 - USART5(Tx) |
| PD2 - USART5(Rx) |
*/
void USART5_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART3 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
/* Configure USART5 Tx (PC.12) as alternate function push-pull */
GPIO_Tx_Usart5_Config(GPIO_Mode_AF_PP);
/* Configure USART5 Rx (PD.02) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_Config();
USART_Init(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
Uart_NVIC_Configuration(UART5);
}
赞
0
评论
回复
支持
反对
wkuang
回答时间:2014-4-18 23:03:07
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
建议直接配寄存器,用查询的方式,把需要配置的管教映射,时钟什么的通通重新配置一次。
中断的话等查询方式调试通过了再试试
赞
0
评论
回复
支持
反对
feiante-155820
回答时间:2014-4-19 23:51:41
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
你的不通是什么意思呢?连上仿真器,看看能不能进入中断,是不能进入发送还是不能进入接收。
赞
0
评论
回复
支持
反对
fengye5340
回答时间:2014-4-20 10:38:40
a0a.1 0b0c
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
1、你发送0x55字符的时候不要使用总断实现,而是采用查询实现。
2、不要在串口接收中断接收字符后禁止接收中断。
3、把中断优先级都设置为0 0
再试一下,网上完善的例程或者官网例程很多,代码可以优化
赞
0
评论
回复
支持
反对
1
2
/ 2 页
所属标签
相似问题
关于
意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号
手机版
快速回复
返回顶部
返回列表
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
/****************************************
* ÎļþÃû £ºusart.c
| PA9 - USART1(Tx) |
| PA10 - USART1(Rx) |
| PA2 - USART2(Tx) |
| PA3 - USART2(Rx) |
| PB10 - USART3(Tx) |
| PB11 - USART3(Rx) |
| PC10 - USART4(Tx) |
| PC11 - USART4(Rx) |
| PC12 - USART5(Tx) |
| PD2 - USART5(Rx) |
**********************************************************************************/
#include "usart.h"
#include "plc.h"
#include
#include
USART_InitTypeDef USART_InitStructure;
void GPIO_Tx_Usart1_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Tx_Usart2_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Tx_Usart3_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART4 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void GPIO_Tx_Usart4_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART4 Tx (PC.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void GPIO_Tx_Usart5_Config(GPIOMode_TypeDef GPIOMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART5 Tx (PC.12) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIOMode;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void USART_Config(void)
{
/* USART mode config */
USART_InitStructure.USART_BaudRate = 250000; //ÅäÖÃUSART1µÄ²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //USART½ÓÊÕ»òÕß´«Êä8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //USART·¢Ë͵ÄֹͣλΪ1λ
USART_InitStructure.USART_Parity = USART_Parity_No ; //¶¨ÒåUSARTµÄÆæÅ¼Ð£ÑéλΪÎÞ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //¶¨ÒåUSARTµÄÓ²¼þÁ÷¿ØÄ£Ê½µÄRTSºÍCTSʹÄÜ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ʹÄÜ·¢ËͺͽÓÊÕģʽ
}
/*
* º¯ÊýÃû£ºUART_NVIC_Configuration
* ÃèÊö £ºUARTÖжÏÓÅÏȼ¶ÅäÖÃ
*/
void Uart_NVIC_Configuration(USART_TypeDef* USARTx)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //ÉèÖÃÓÅÏȼ¶·Ö×é
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÇÀÕ¼ÓÅÏȼ¶Îª×î¸ß0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //ÏìÓ¦ÓÅÏȼ¶Îª×î¸ß0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ͨµÀʹÄÜ
switch (*(uint32_t*)&USARTx)
{
case USART1_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case USART2_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case USART3_BASE:
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case UART4_BASE:
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
case UART5_BASE:
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_Init(&NVIC_InitStructure);
break;
default:
break;
}
}
/*
* º¯ÊýÃû£ºUSART1_Config
* ÃèÊö £ºUSART1 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA9 - USART1(Tx) |
| PA10 - USART1(Rx) |
*/
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_Tx_Usart1_Config(GPIO_Mode_AF_PP);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_Config();
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
Uart_NVIC_Configuration(USART1);
}
/*
* º¯ÊýÃû£ºUSART2_Config
* ÃèÊö £ºUSART2 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA2 - USART2(Tx) |
| PA3 - USART2(Rx) |
*/
void USART2_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART2 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_Tx_Usart2_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PA.03) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_Config();
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
Uart_NVIC_Configuration(USART2);
}
/*
* º¯ÊýÃû£ºUSART3_Config
* ÃèÊö £ºUSART3 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PB10 - USART3(Tx) |
| PB11 - USART3(Rx) |
*/
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART3 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* Configure USART2 Tx (PB.10) as alternate function push-pull */
GPIO_Tx_Usart3_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_Config();
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
Uart_NVIC_Configuration(USART3);
}
/*
* º¯ÊýÃû£ºUSART4_Config
* ÃèÊö £ºUSART4 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PC10 - USART4(Tx) |
| PC11 - USART4(Rx) |
*/
void USART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART4 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
/* Configure USART4 Tx (PC.10) as alternate function push-pull */
GPIO_Tx_Usart4_Config(GPIO_Mode_AF_PP);
/* Configure USART2 Rx (PC.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_Config();
USART_Init(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
Uart_NVIC_Configuration(UART4);
}
/*
* º¯ÊýÃû£ºUSART5_Config
* ÃèÊö £ºUSART5 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PC12 - USART5(Tx) |
| PD2 - USART5(Rx) |
*/
void USART5_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* config USART3 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
/* Configure USART5 Tx (PC.12) as alternate function push-pull */
GPIO_Tx_Usart5_Config(GPIO_Mode_AF_PP);
/* Configure USART5 Rx (PD.02) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_Config();
USART_Init(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
Uart_NVIC_Configuration(UART5);
}
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
中断的话等查询方式调试通过了再试试
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通
2、不要在串口接收中断接收字符后禁止接收中断。
3、把中断优先级都设置为0 0
再试一下,网上完善的例程或者官网例程很多,代码可以优化