<stdio.h>, snprintf() not implemented?
Posted: Wed 15. May 2024, 00:21
Hi,
I'm attempting to convert a floating point value as a string in order to send it over RS-232 ASCII serial.
Naturally, I tried using snprintf() and sprintf() from stdio.h, but it seems to make the PEAK RS-232 device hang as soon as either function is called.
As a sanity check I compiled the following code with normal GCC compiler and it worked as expected:
I then tested with the CAN_ECHO example project. I compiled the CAN_ECHO example project, loaded it to the RS-232 device, and ensured it worked as expected.
Next, I added the code to the example project:
It compiles, but when I flashed it the device the CAN messages I sent were no longer echoing back.
Has anyone else encountered this error? Is snprint() etc. not implemented?
What is the work around for transmitting ASCII representation of floating point values?
Thanks
I'm attempting to convert a floating point value as a string in order to send it over RS-232 ASCII serial.
Naturally, I tried using snprintf() and sprintf() from stdio.h, but it seems to make the PEAK RS-232 device hang as soon as either function is called.
As a sanity check I compiled the following code with normal GCC compiler and it worked as expected:
Code: Select all
#include <stdio.h>
int main() {
char buffer[100]; // Buffer to hold the output string
float myFloat = 3.14159265;
// Use snprintf to format the float to 3 decimal places
snprintf(buffer, sizeof(buffer), "%.3f", myFloat);
// Print the formatted string
printf("Formatted Float: %s\n", buffer);
return 0;
}
Next, I added the code to the example project:
Code: Select all
#include <stdio.h>
Code: Select all
char buffer[100]; // Buffer to hold the output string
float myFloat = 3.14159265;
// Use snprintf to format the float to 3 decimal places
snprintf(buffer, sizeof(buffer), "%.3f", myFloat);
Has anyone else encountered this error? Is snprint() etc. not implemented?
What is the work around for transmitting ASCII representation of floating point values?
Thanks