野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10805|回复: 2

STM32F103串口问题

[复制链接]
发表于 2016-11-30 20:58:43 | 显示全部楼层 |阅读模式
大家好,最近调串口1,发现程序停在 while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)处,不走了,下面是端口的初始化,谁遇到过这个问题啊,串口2是可以调通的
void  usart_rcc_init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}
void  usart_gpio_init(void)
{
    GPIO_InitTypeDef gpio_init_struct;
   
    gpio_init_struct.GPIO_Pin = GPIO_Pin_9;
    gpio_init_struct.GPIO_Mode = GPIO_Mode_AF_PP;
    gpio_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &gpio_init_struct);
   
    gpio_init_struct.GPIO_Pin = GPIO_Pin_10;
    gpio_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &gpio_init_struct);
}

void usart_param_init(void)
{
    USART_InitTypeDef usart_init_struct;
    usart_init_struct.USART_BaudRate = 115200;
    usart_init_struct.USART_WordLength = USART_WordLength_8b;
    usart_init_struct.USART_StopBits = USART_StopBits_1;
    usart_init_struct.USART_Parity = USART_Parity_No;
    usart_init_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    usart_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
   
    USART_Init(USART1, &usart_init_struct);
}



回复

使用道具 举报

发表于 2016-11-30 21:30:56 来自手机 | 显示全部楼层
具体的对比光盘里面配套的历程 看看有什么区别
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-12-1 10:32:38 | 显示全部楼层
fire 发表于 2016-11-30 21:30
具体的对比光盘里面配套的历程 看看有什么区别

串口2是通的,这个串口1的初始化设置都是参照那个来的
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-20 12:30 , Processed in 0.030274 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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