Skip to main content
Visitor II
March 8, 2024
Question

hexdecimal number to send UART

  • March 8, 2024
  • 2 replies
  • 1341 views

Hi,

I wanted to send hexadecimal numbers through UART. I am using STM32F405. Can it be done.

If I am sending float number as 1.3456 string (text) to windows COM port to  english language windows application field. If for example regional settings being changed on the windows to german language and return float number as 1,3456.Sending the float number as hexadecimal will that sort out the problem. Any suggestions?

 

 

 

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    March 8, 2024

    Hello @cjaya.2 

    For sending hexadecimal number over UART, yes this is possible. But for the language problem that you are facing, we don't have any idea on that because it depends on the application on your PC and not the STM32.

    Best Regards.

    STTwo-32 

    Graduate II
    March 8, 2024

    I think the proposed method is to send IEEE-754 floats/double in an ASCII form. Obviously that would immediately double the size of transmitted data.

    One could send arrays of floats/doubles directly as 8-bit bytes, a 32-bit float would take 4-bytes and 64-bit double would take 8-bytes. The sort of way we'd normally store in memory, or in a file.

    The byte ordering would depend on the endian ordering, but ARM and PC are typically small/little endian

    Graduate II
    March 8, 2024

    Surely generating hex, or other bases, is a very basic task, should be able to do from first-principles.

    itoa() is a frequently used library method https://cplusplus.com/reference/cstdlib/itoa/

    I tend to use table/shift methods for high efficiency.

    For numeric formatting look at locale settings.