0 Members and 1 Guest are viewing this topic.
float value = 21.54; char buf[20]; snprintf(buf, sizeof(buf), "%f", value); rc = FatFs.write(buf, 20, &bw);
If I swap out 'buf' in the write statement to "21.54" it works fine and writes to the card, but if I use 21.54 it gives me an incompatibility error, and with buf it seems to just write out whatever's in the format section of snprintf.
Quote from: Jon86 on November 01, 2013, 11:37:20 pmIf I swap out 'buf' in the write statement to "21.54" it works fine and writes to the card, but if I use 21.54 it gives me an incompatibility error, and with buf it seems to just write out whatever's in the format section of snprintf.I was suggesting replacing value (not buf) with "21.54" (with quotes).snprintf(buf, sizeof(buf), "%f", "21.54"); <-- i expect the compiler to sort out the correct parm addressing format.and then tryingsnprintf(buf, sizeof(buf), "%f", *value); <--this is just a guess of sorts
Quote from: Jon86 on November 01, 2013, 11:37:20 pmIf I swap out 'buf' in the write statement to "21.54" it works fine and writes to the card, but if I use 21.54 it gives me an incompatibility error, and with buf it seems to just write out whatever's in the format section of snprintf.That it writes out the format section tells me that your compiler isn't set to using full printf support, that is usually switched off when building for microcontrollers since it takes quite a lot of space to support floats...
If you are doing simple arithmetic on a microcontroller it may not be appropriate to bring in the complexity of floating point arithmetic and floating point library support.You could consider using integers and fixed point arithmetic instead, and then conversion to a string would be much easier. You could use itoa() and some simple character processing to put the decimal point in the right place.
No idea, never used it...For CCStudio it is a command line option: http://processors.wiki.ti.com/index.php/Printf_support_in_compiler. Could also be that you need to link to a different library.Another possibility would be to not use floats at all, something likehttp://forum.43oh.com/topic/1954-using-the-internal-temperature-sensor/
snprintf(buf, sizeof(buf), "%f", value); must work
print_float(float f) { int int_part, fraction; int_part = (int) f; fraction = (f - int_part) * 1000.0; // three digits after decimal. printf("%d.%03d", int_part, fraction);}
IT WORKS! (I think)
I expect this will be easy in code composer studio
It will fail if the float type is negative.
You can store the data in milikelvins