野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1769|回复: 2

STM32F103C8T6核心板串口3无法发送数据

[复制链接]
发表于 2023-5-3 18:17:45 | 显示全部楼层 |阅读模式
核心板的串口3是PB11和PB10,我写入了代码,一直发不出去,在等待发送清零处卡死。
配置串口三的代码如下:


GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
       
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
       
    // 配置PB10引脚为复用推挽输出
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        // 配置PB11引脚为浮空输入
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
    // 配置USART3
    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_Tx | USART_Mode_Rx;
    USART_Init(USART3, &USART_InitStructure);
       
        // 配置 NVIC 中断优先级
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
   
        // 使能 USART3 接收中断
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
       
    USART_Cmd(USART3, ENABLE);

发送信息函数如下:


void USART3_SendString(uint8_t* str)
{
    while(*str != '\0')
        {
                while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
                USART_SendData(USART3, (uint16_t)*str++);
                while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
        }
}
在这两个等待while 的,它们的条件一直都拉不下来,死循环卡死在这里。
串口1 和 2 是正常工作。

有谁知道是为什么吗?

回复

使用道具 举报

发表于 2023-5-4 14:07:35 | 显示全部楼层
能接收吗
回复

使用道具 举报

 楼主| 发表于 2023-8-4 14:07:21 | 显示全部楼层

我后面找到解决办法了,是TTL线故障了  
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-27 16:23 , Processed in 0.029291 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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