cancel
Showing results for 
Search instead for 
Did you mean: 

hi friends , I want to send and receive a float value with uart without converting it to a string. How can I do that

newlearner
Associate II
 
4 REPLIES 4

The data representation of a 32-bit float is contained in 4-bytes, you could send the data as a collection of 4 bytes.

You might want to put the data within a larger data structure you can synchronize and validate on the receiving end.

One could perhaps learn how this works on a PC by saving and retrieving data from a file

float f = 1.2345f;

HAL_UART_Transmit(&hUart, (void *)&f, sizeof(float), 1000);

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

Hello, I tried, but the number is not gone, the letters are coming.

 HAL_UART_Transmit(&huart2, (void*)&f, sizeof(float),HAL_MAX_DELAY);
     HAL_Delay(300); 

Ok, but I think that's more of a problem of not understanding the basics of data representation. And what you're asking.

It would help you significantly to learn some basic computer concepts and programming in C before embarking on embedded programming.

Going to assume you aren't familiar with binary representation, or exponent/mantissa concepts for floating point numbers. The computer isn't doing the math on ASCII decimal digits here.

IEEE-754 floating point https://en.wikipedia.org/wiki/IEEE_754

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

https://www.geeksforgeeks.org/convert-floating-point-number-string/

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