你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 519|回复: 3

串口调试完成,库函数法

[复制链接]

52

主题

3313

回帖

61

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2015-1-13 09:18:50 | 显示全部楼层 |阅读模式
自动返回你输入的字符
捕获222.PNG


主函数如下:
  1. #include "stm32f0xx.h"
  2. #include "Usart1.h"

  3. unsigned char Uart_buf[2]={0x00,0x00}; //缓冲接收缓冲器

  4. void led_gpio_config()
  5. {
  6.         GPIO_InitTypeDef GPIO_InitStructure;
  7.         RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_GPIOA, ENABLE);     //总线使能

  8.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;                 //Pin 5
  9.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ;            //输出模式
  10.   GPIO_InitStructure.GPIO_OType        =GPIO_OType_PP ;            //推挽输出
  11.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;             //配置为上拉
  12.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;       //50MHz
  13.   GPIO_Init(GPIOA, &GPIO_InitStructure);      
  14. }


  15. int main(void)
  16. {              
  17.        
  18.         led_gpio_config(); //IO口初始化
  19.        
  20.         GPIO_SetBits(GPIOA,GPIO_Pin_5);
  21.         USART_Config();
  22.        
  23.         printf("STM32-NUCLEO-072RB开发板初始化成功!\r\n");       
  24.         printf(""hello world"!\r\n");       
  25.         printf("\r\n 你输入的字符是:\r\n");
  26.         while (1)
  27.          {
  28.                  Uart_buf[0]=Uart_RChar();
  29.                  if(Uart_buf[0]!=NULL)
  30.                                  printf("你输入的字符是:%x\r\n",Uart_buf[0]);       
  31.          }
  32.        
  33. }
复制代码



回复

使用道具 举报

307

主题

3125

回帖

0

蝴蝶豆

论坛元老

最后登录
2020-7-17
发表于 2015-1-13 09:24:24 | 显示全部楼层
谢谢~
回复 支持 反对

使用道具 举报

52

主题

3313

回帖

61

蝴蝶豆

论坛元老

最后登录
2020-12-9
 楼主| 发表于 2015-1-13 09:32:50 | 显示全部楼层
串口打印的,printf重定向部分:(在此感谢“山河”网友的指点啊,不知道论坛ID是啥)
  1. /*******************************************************************************
  2. 函数名称:fputc(int ch, FILE *f)
  3. 功    能:串口实现Printf()函数功能
  4. 参    数:无
  5. 返回值  :
  6. ********************************************************************************/
  7. int fputc(int ch, FILE *f)
  8. {
  9.   while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
  10. <font color="#ff0000">                ;</font>
  11.         USART_SendData(USART1,(uint8_t)ch);
  12.   return (ch);
  13. }
复制代码
关于上面的那个分号,如果在while后面,会有警告
回复 支持 反对

使用道具 举报

0

主题

9

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2015-1-13 10:58:03 | 显示全部楼层
帮顶 ,感谢分享
回复 支持 反对

使用道具 举报

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版