<stdlib.h>
-
字符串转整型:
int atoi(const char *str)
uint8_t temp_len_n=0,temp_len=0;
char temp_data[10]={“123466”};
temp_len=atoi(temp_data); -
printf中fputc重写
需要先包含#include “stdio.h”
然后添加代码如下:
int fputc(int ch,FILE *f)
{
uint8_t temp[1]={ch};
HAL_UART_Transmit(&huart1,temp,1,2);
return ch;
}
使用HAL库,对UART1操作
写调用这个函数即可在串口1收到内容。
printf(“Task running\r\n”); -
任意多个参数转为字符串:如MQTT的三要素配置
sprintf(Nb.Send_AT_buffer,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",“AT+MQTTCFG=”",Nb.ProductKey,ip,"",",port,","",id,"",60,"",Nb.DeviceName,"&",Nb.ProductKey,"","",Nb.DevicePassword,"",1\r\n"); -
List item
#ifdef DBUG_PRNTF
printf("\n%s\n",“M5311rst”);//测试功能
#endif