打印
[STM32]

stm32f103ze 寄存器-串口问题

[复制链接]
559|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
1349236685|  楼主 | 2017-5-4 20:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

大神帮我看看,这个串口在keil不报错,可是在串口助手中没法接收数据,大神帮我看看哪里有问题

#include "stm32f10x_conf.h"
#include "stm32f10x_usart.h"

void usart_init (void)
{
                //定义参数
        USART_InitTypeDef USART_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
        
        //使能及复用时钟
        RCC_APB2PeriphClockCmd (//RCC_APB2Periph_AFIO|     //串口重映射功能PB10 PB11
                                                                                                        RCC_APB2Periph_GPIOA|
                                                                                                        RCC_APB2Periph_USART1,ENABLE);
        
        //PA9复用推挽50M输出 PA10上拉输入
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        //PA10 上拉输入
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        //串口复位
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
        
        //串口初始化结构体
        USART_InitStructure.USART_BaudRate =9600;
        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(USART1,&USART_InitStructure);
        
        //串口整体使能
        USART_Cmd(USART1, ENABLE);
        
}

char data;
void usart_senddata (char data)
{
        USART_SendData(USART1, data);
}

char usart_receive (void)
{
        data=USART_ReceiveData(USART1);
        return data;
}        


#include "stm32f10x_conf.h"
//#include "stm32f10x_rcc.h"
#include "USART.H"
#include "stm32f10x_usart.h"

extern char data;

int main (void)
{
        usart_init ();
        while(1)
        {
                usart_senddata (usart_receive());
        }
}

相关帖子

沙发
xjycug| | 2017-5-4 21:48 | 只看该作者
程序不全,如果是在线调试,直接用示波器看看吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

33

主题

71

帖子

0

粉丝