Hello!
I've been trying to get a function to work for awhile and it's driving me nuts. I know there's an alternative in dtostrf(...) but now I'm just wondering what exactly is the problem even if I might not use it for my project (motion tracker/display using MPU-6050 data to visualize on a small SPI connected OLED) at this rate.
void XBeeSendInt(int16_t number) { char* str = ConvertIntToStr(number); while(*str) { XBeeSendChar(*str++); } free(str); } void XBeeSendDouble(double dbl) { char* str = ConvertDblToStr(dbl); while(*str) { XBeeSendChar(*str++); } free(str); } char* ConvertIntToStr(int16_t number) { int length = snprintf( NULL, 0, "%d", number ); char* str = malloc( length + 1 ); snprintf( str, length + 1, "%d", number ); return str; } char* ConvertDblToStr(double dbl) { int length = snprintf( NULL, 0, "%f", dbl ); char* str = malloc( length + 1 ); snprintf( str, length + 1, "%f", dbl ); return str; }
So the int code works pretty well (I have it outputting to putty via uart) though I haven't really tried a whole bunch of values, but it does send at least. The character array that gets made for the converted int is a little bit past the starting address for the SRAM (0x002056).
However, the string for the double gets put at 0x005985 and all stored values in that section of memory are FF. It doesn't appear to be working at all. I've tried %f and %lf and I've made sure to check the linker (below) is correct to allow full floating point for vprintf().
-Wl,-Map="$(OutputFileName).map" -Wl,-u,vfprintf -Wl,--start-group -Wl,-lm -Wl,-lprintf_flt -Wl,--end-group -Wl,--gc-sections -mmcu=atxmega128a1u -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\XMEGAA_DFP\1.1.68\gcc\dev\atxmega128a1u"
I'm not sure what the problem is at all at this point and could really use some help. Thank you!