This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How Can I sent to serial port a float?

Hi!
In my project i sent to serial port a int :

unsigned int X;
        putchar(X);
        putcahr(X>>8);

and everything to work OK!!

but if i want change my data type and use float, i cant do

putchar(X>>8)

.
I trying it:

float X _at_ xxxxx;


and with a function i read all adress of my data but it no work.

Any idea to do it??
thanks

Parents
  • Either send the floating point number as ASCII, i.e. the result of printf(), sprintf(), ...

    Or make an experiment if you can transfer the four raw bytes (possibly with a byte swap) and have the PC pick up the result.

    If the numbers are following the IEEE standard, then they should be stored in a compatible way so it should be possible to set a byte pointer to the address of the float and then send four bytes.

    This gives the smallest code and maximum precision in the transfer but you need to define in which order the bytes arrive so the PC program knows what to do.

Reply
  • Either send the floating point number as ASCII, i.e. the result of printf(), sprintf(), ...

    Or make an experiment if you can transfer the four raw bytes (possibly with a byte swap) and have the PC pick up the result.

    If the numbers are following the IEEE standard, then they should be stored in a compatible way so it should be possible to set a byte pointer to the address of the float and then send four bytes.

    This gives the smallest code and maximum precision in the transfer but you need to define in which order the bytes arrive so the PC program knows what to do.

Children