cancel
Showing results for 
Search instead for 
Did you mean: 

Send float to UART

Indois
Associate II

Hello,

I would like to send float numbers to UART and then check it in terminal using UART <-> USB converter. Could you provide any function which transmits float to UART? I am using STM32CubeIDE environment.

Thank you.

8 REPLIES 8
PSoco.1
Associate III

vague question... does this go to a console and you want it in human readable format? there is a program that receives the data?

you see, when you transmit data you usually chose a protocol. in a sense you send the data and establish a contract so that both sender and reciever talks the same 'language'. the protocol should be chosen to make your life as easy as possible. before going for the actual code you should have a clear understanding of where you want to go.

suppose you want to send over UART a float, you can send it in binary or use a human readable format:

char temp[32];
int c= snprintf(temp, sizeof(temp),"%f\r\n", number);
send_uart(temp, c);

but you can use standard functions to do that like snprintf. then about send_data... you should start by looking into ST HAL and SDK

Indois
Associate II

I would like to send float numbers in human readable format, just to check it in console. I am using STM32 LL (Low Layer) libraries which include only LL_USART_TransmitData9 (for 9 bit transmission) and LL_USART_TransmitData8 (8 bit transmission) functions.

Convert to an ASCII string using sprintf(), dtoa() and then push that as a block of 8-bit data

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

I receive such message:

 0693W00000AOIGtQAP.png 

So enabled the -u _printf_float and now errors are displayed:

\stm32cubeide\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: Test.elf section `.text' will not fit in region `FLASH'

stm32cubeide\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: Test.elf section `._user_heap_stack' will not fit in region `RAM'

stm32cubeide\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: region `RAM' overflowed by 128 bytes

stm32cubeide\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 11792 bytes

Not sure what STM32 part you're using, but it seems to not have enough memory to load the entire library and your code.

Perhaps dtoa() or ftoa() have a smaller foot-print, or you need to take a different approach.

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

I am using STM32L0 which has only 2KB of RAM and 16KB of Flash memory. Are there any more economical ways to send Float over UART?

PSoco.1
Associate III

not out of the box. that means you have to code and/or port libraries and spend a lot of time in optimizing your code. for floating point there is a https://github.com/ulfjack/ryu library. you should remove all standard libraries and just use a float to ascii string like ftoa. but with 16kb of flash I doubt is feasible in the first place, unless your program only prints floats and the rest is just trivial like a sensor. then if a float is too expensive, people tend to print the value in hex and use a program with a nice UI to convert the hex to a float, you can even draw a gas gauge :>. maybe you should review your plans. good luck...

Paul1
Lead

If you need it converted by a terminal program check out CoolTerm at http://freeware.the-meiers.org/

Roger has a mode that will graph data received.

Possibly with a bit of a donation he could add a mode that would convert your data, or even graph it.

I believe there is also modes for deciphering packets, whoch means if you frame your floats with appropriate chars you might be able to write your own macro to decipher them.

Paul