3561|2

8

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

UART1不能发送数据 [复制链接]



我像发个数据05到串口上,函数如下,但是串口上显示不出来,请问下这是什么问题?


#include"stm32f10x.h"

 GPIO_InitTypeDef GPIO_InitStructure;
 USART_InitTypeDef  USART_InitStructure;

 


 int  main()
 {

     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_USART1,ENABLE);

   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;         //TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;    //RX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

  // USART_StructInit(&USART_InitStructure);

        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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
               USART_Init(USART1,&USART_InitStructure);

     
   
       USART_Cmd(USART1, ENABLE);

//   USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
      //     USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
 
 USART_SendData(USART1, 0x05);


另外,如果调用了函数
USART_StructInit(&USART_InitStructure);
是不是就不需要这些设置了:
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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
               USART_Init(USART1,&USART_InitStructure);
因为USART_StructInit(&USART_InitStructure);就是配置各成员的缺省值。
请大家指点指点!谢谢!
[ 本帖最后由 vipczx 于 2011-9-18 16:38 编辑 ]
此帖出自stm32/stm8论坛

最新回复

void UART1Init(void) {         GPIO_InitTypeDef GPIO_InitStructure;         USART_InitTypeDef USART_InitStructure;         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;         GPIO_Init(GPIOA, &GPIO_InitStructure);         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;         GPIO_Init(GPIOA, &GPIO_InitStructure);         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); } void UART1SendByte(unsigned char SendData) {                   USART_SendData(USART1,SendData);         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);              }  详情 回复 发表于 2011-9-19 17:34
点赞 关注
 

回复
举报

406

帖子

0

TA的资源

纯净的硅(中级)

沙发
 

你可以参照下我的程序

void UART1Init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        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);
}




void UART1SendByte(unsigned char SendData)
{          
        USART_SendData(USART1,SendData);
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
            
}
此帖出自stm32/stm8论坛
 
个人签名STM32 开发板  带CAN  RS485 接口
http://shop66177872.taobao.com
 

回复

8

帖子

0

TA的资源

一粒金砂(中级)

板凳
 
你好!
这样写可以显示出“A”
while(1)
{
USART_SendData(USART1,0x41);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
}

但是写成
USART_SendData(USART1,0x41);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
while(1)
{
.........
}
就显示不了了。这是怎么回事啊

[ 本帖最后由 vipczx 于 2011-9-19 21:53 编辑 ]
此帖出自stm32/stm8论坛
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表