Skip to main content
newlearner
Associate II
April 8, 2021
Question

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

  • April 8, 2021
  • 1 reply
  • 3315 views

..

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
April 8, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..
newlearner
Associate II
April 8, 2021

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); 

Tesla DeLorean
Guru
April 8, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..