The printf function in the AVR GCC does not support%f output
Note that the float double type data in GCC is treated as single precision (4 bytes)
There are two ways: 1, the floating-point number is decomposed into 4 bytes, sent separately, the receiver and then the 4 bytes merged into the floating-point number
Examples are as follows:
#include <stdio.h>typedef union{floatF; unsignedCharu[4];} Float4byte;intMainvoid) {Float4byte m1,m2; M1.F=-1.2356; m2.u[0]=m1.u[0];//Let's say this is a transfer process. M2.U[1]=M1.U[1]; M2.U[2]=M1.U[2]; M2.U[3]=M1.U[3];printf"m1=%f", M1.F); printf ("m2=%f", M2.F); return 0;}
Running Result: m1=-1.235600 m2=-1.235600
2, the floating-point conversion string, the word character sent out, the receiver will then combine these characters into a string, if you want to operation and then convert the string into floating point number.
such as string concatenation using the Sprint function
3, the floating-point number amplification *10, *100, *1000, etc., converted into integer
4. sprintf and floating-point support with AVR GCC
sprintf is easy to use, include <stdio.h>. However, if you want to format the floating-point number, you need the following steps, the simple description is: 1. Need and libprintf_flt.a libm.a Link 2. Need to pass link option:-wl,-u,vfprint
Serial output Float type data