DAVE 4.2.2 - sprintf doesn't work

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi

I'm trying to print 3 variables on an SD card .txt file each script cycle. For that I need to pass a string in the f_write() function, so I want to use the sprintf() function to insert the variables in the string.

The code I'm using is something like this (it is based in the FATFS APP example):

char buff[22];
float Vo = 4.216;
float i = 0;
float soc = 100;


sprintf(buff, "%.5f,%.5f,%.1f", Vo, i, soc);
res = f_write(&fil, &buff, 22, &bw);


The problem is that this doesn't print anything more than ",," in the buff[] string. After the ",," there is a lot of garbage (the other 20 elements), but in the middle there's nothing.

This code works fine on Visual Studio, but not on DAVE...

Thanks in advance.

EDIT: I've tested now the sprintf() function with ints instead of floats and it works. It just doesn't like floats...
0 Likes
2 Replies
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

You will need to enable "Add floating point support for printf" in the Project properties > ARM-GCC Linker > General.

Best regards,
Jesus
0 Likes
Not applicable
Thanks Jesus! It is working now!
0 Likes