STM32中printf重定向到串口
2015-03-31 10:04
302 查看
STM32中printf重定向到串口
转载自:http://blog.csdn.net/wdscq1234/article/details/7944036
学习STM32过程中,经常打交道的莫过于串口,你可以将任何信息,当然重要的是调试信息打印到串口中输出,总是用一个字节发送函数或者字符串发送函数
总是有些不放便,之前编程中熟悉的莫过于printf了,下面就给出了用printf打印到串口的方案,当然方案不止一个,仅供参考。
1、 添加printf的头文件 #include <stdio.h>
2、重写int fputc(int ch, FILE *f)函数
int fputc(int ch, FILE *f);
函数
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
3、修改一下选中Use MicroLIB Target——Code Generation——选中Use MicroLIB
这样就可以像以前那样使用printf了。
重定向C库函数printf到USART1
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
return (ch);
}
重定向C库函数scanf到USART1
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}
转载自:http://blog.csdn.net/wdscq1234/article/details/7944036
学习STM32过程中,经常打交道的莫过于串口,你可以将任何信息,当然重要的是调试信息打印到串口中输出,总是用一个字节发送函数或者字符串发送函数
总是有些不放便,之前编程中熟悉的莫过于printf了,下面就给出了用printf打印到串口的方案,当然方案不止一个,仅供参考。
1、 添加printf的头文件 #include <stdio.h>
2、重写int fputc(int ch, FILE *f)函数
int fputc(int ch, FILE *f);
函数
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
3、修改一下选中Use MicroLIB Target——Code Generation——选中Use MicroLIB
这样就可以像以前那样使用printf了。
重定向C库函数printf到USART1
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
return (ch);
}
重定向C库函数scanf到USART1
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}
相关文章推荐
- 实现STM32的串口数据发送和printf函数重定向
- STM32输出调试信息-printf重定向到串口
- 【stm32】实现STM32的串口数据发送和printf函数重定向
- STM32中ADC的使用/printf函数重定向串口显示内部温度传感器测量值
- STM32中printf重定向到串口
- STM32中printf重定向到串口
- 7、STM32 的串口编程(printf 重定向)
- 【stm32】实现STM32的串口数据发送和printf函数重定向
- stm32_013_STM32printf()函数重定向到串口
- 【STM32】keil MDK下重定向printf到串口(基于STM32CubeMX)
- STM32学习笔记-配置串口,printf重定向
- 在stm32 单片机程序中使用printf()进行串口调试
- (STM32 A串口2)接收(STM32 B数据printf2),同时STM32 A使用串口1printf给电脑
- keil C51 printf 重定向 串口
- Keil C51重定向printf到串口
- STM32 printf 函数重定向
- STM32串口打印printf
- STM32 学习九 通过USART实现printf重定向
- 关于printf重定向到串口
- 关于stm32中printf函数重定向问题