OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3501|回复: 1

写一个关于串口的代码,重定义输入的时候老是显示链接错误,不知道那里错了求讲解

[复制链接]

15

主题

39

帖子

0

精华

新手上路

积分
40
金钱
40
注册时间
2015-2-24
在线时间
4 小时
发表于 2015-3-30 16:39:52 | 显示全部楼层 |阅读模式
5金钱
其中配置是


错误提示,我当我把int fgetc(FILE *fp)
这个函数去掉的时候,就就没有错误提示了,但是我不知道int fgetc(FILE *fp)
到底那里有问题。求赐教

[mw_shl_code=c,true]#include "usart.h" /**------------------------------------------------------- * @函数名 main * @功能 主函数 * @参数 无 * @返回值 无 ***------------------------------------------------------*/ int main(void) { uint8_t Str[80] = {0}; SZ_STM32_COMInit(); /* 串口初始化 */ printf("\n\r WWW.ARMJISHU.COM! \n"); while (1) { scanf("%s", Str); printf("\n\r 输入的字符串是: <%s>\n", Str); } } [/mw_shl_code]


其中usart.h是这样的
[mw_shl_code=c,true]#include "stm32f10x.h" #include <stdio.h> #ifdef __cplusplus extern "C" { #endif void SZ_STM32_COMInit(void); #ifdef __cplusplus } #endif [/mw_shl_code]


[mw_shl_code=c,true]#include "usart.h" void SZ_STM32_COMInit(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* 使能STM32的USART对应GPIO的Clock时钟 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* 初始化STM32的USART的TX管脚,配置为复用功能推挽输出 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA , &GPIO_InitStructure); /* 初始化STM32的USART的RX管脚,配置为复用功能输入 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA , &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; //串口的波特率,例如115200 最高达4.5Mbits/s USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据字长度(8位或9位) USART_InitStructure.USART_StopBits = USART_StopBits_1; //可配置的停止位-支持1或2个停止位 USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件流控制 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //双工模式,使能发送和接收 /* 根据传入的参数初始化STM32的USART配置 */ USART_Init(USART1, &USART_InitStructure); /* 使能STM32的USART功能模块 */ USART_Cmd(USART1, ENABLE); } /* 重定义fputc函数 如果使用MicroLIB只需要重定义fputc函数即可 */ int fputc(int ch, FILE *f) { /* e.g. write a character to the USART */ USART_SendData(USART1, (uint8_t) ch); /* Loop until the end of transmission */ while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); return ch; } int fgetc(FILE *fp) { int ch = 0; while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); ch = (int)USART1->DR & 0xFF; putchar(ch); //回显 return ch; }[/mw_shl_code]


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2015-3-30 18:39:00 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-24 06:39

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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