专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
请问M3串口发送不成功可能是什么原因
2019-07-14 17:35
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
7067
15
1656
片子用的
STM32
F103C8T6,之前正常,后来板子上的串口位置换了,就把串口换了一下,三个串口都用
串口1和串口3都发送不出去
USART_SendData(USART1, (u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
跑到这里,就一直检测标志位了
串口2能够发送成功,配置一样,试了两块板子,效果一样
可能是哪里的问题呢?
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
15条回答
wang222221
2019-07-15 04:49
void UART1_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
Uart1Conf.RXpoint = 0;
Uart1Conf.RXStart = Uart1Conf.RXpoint;
Uart1Conf.RXlenth = 0;
Uart1Conf.TXlenth = 0;
Uart1Conf.Time = 0;
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
原来用着好好的啊 就是换了一下顺序
串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不
加载中...
查看其它15个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
Uart1Conf.RXpoint = 0;
Uart1Conf.RXStart = Uart1Conf.RXpoint;
Uart1Conf.RXlenth = 0;
Uart1Conf.TXlenth = 0;
Uart1Conf.Time = 0;
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
原来用着好好的啊 就是换了一下顺序
串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不
一周热门 更多>