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