2021-05-13 07:34 AM
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.
2021-05-13 08:17 AM
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
2021-05-13 01:10 PM
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.
2021-05-13 01:24 PM
Convert to an ASCII string using sprintf(), dtoa() and then push that as a block of 8-bit data
2021-05-13 04:59 PM
I receive such message:
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
2021-05-13 05:03 PM
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.
2021-05-13 11:57 PM
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?
2021-05-14 12:30 AM
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...
2021-05-14 04:33 AM
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