2018-11-20 12:55 AM
Hi all,
I have a problem to show float numbers via sprintf, I'm working with STM32F334
I did a program to print via serial the voltage read from ADC, in float format like %4.2f, the problem is that the first time the sprintf generate a valid string with decimal separator, but the next iterations not.
I followed the tip recommended for @Hae Ryon Jung in this entry of forum, but I didn't get a good result
Any idea?
This is the code:
adcVal = HAL_ADC_GetValue(&hadc1);
adcRes = adcVal*3.3/4096;
sprintf(buffTmp, "[%d]ADC %d %4.2f V\n\r", (int) counter, (int)adcVal, adcRes);
This is the output:
[0]ADC 2531 2.04 V
[1]ADC 2493 204 V
[2]ADC 2495 204 V
Thanks for your support
Regards
Jordi
2018-12-17 04:23 AM
Dear all,
ok ... It's a little shameful, but the problem was a stack fail. I defined the task stack with 512 bytes, and it was not enough to use sprintf with floats. The example works, but it does not work well.
So now it is fixed.
Thanks for all you support.
Regards
Jordi