Skip to main content
EOzde.1
Associate III
October 6, 2021
Question

How to transmit and receive float type variable with TCP LwIP?

Hi,

I am trying to send and receive the float variable between STM32H745 and my PC. I can only transmit and receive strings. Is it even possible to handle any type of data rather than string.

Thank you.

This topic has been closed for replies.

2 replies

TDK
October 6, 2021

The chip doesn't care how you're interpreting data bytes. Treat the value as raw data and cast it to uint8_t pointer.

float value = 123.4f;

TransmitData((uint8_t *) &value, 4);

Do the reverse on the PC:

float value = 0.0f;

ReceiveData((uint8_t *) &value, 4);

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
October 6, 2021

All just a collection of bytes. Data Representation 101

Typically using IEEE-754 data format for float/double variables. Mantissa/Exponent forms.

https://en.wikipedia.org/wiki/IEEE_754

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..