#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
/*
* 描述: HAL库实现多串口使用printf输出
* 参数: huart:对应的串口结构体
* 返回: 无*/
void Uart_printf(UART_HandleTypeDef *huart,char *format, ...)
{
char buf[512]; //定义临时数组,根据实际发送大小微调
va_list args;
va_start(args, format);
uint16_t len = vsnprintf((char *)buf, sizeof(buf), (char *)format, args);
va_end(args);
HAL_UART_Transmit(huart,(u8 *)buf,len,1000);
}
使用时:
Uart_printf(&huart1,"hello world");
Uart_printf(&huart3,"scr_vp.txt=\" %.3lf\"\xff\xff\xff", vpp_dif);//串口屏实时显示
使用浮点数时勾选以上两项