2021-12-20 04:43 PM
Hi all i am facing a problem with sprintf . the %u,%d are working fine in sprintf but the %f is throwing some garbage value in my code any thoughts please share me here. i have shared a snippet of my code over here.
float Channel_5_Volt;
Channel_5_Volt = ((float)Adc_5_Data/4095)*3.3;
sprintf(Buf,"adc0 %f \r\n", Channel_5_Volt);
HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
Solved! Go to Solution.
2021-12-20 05:04 PM
Thankyou for the reply I have not added the two function and now i added it and also checked it is working fine. Thankyou
HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
You should use strlen here and not sizeof.
Thakyou i will change it.
2021-12-20 04:53 PM
Did you enable printf support in your program?
> HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
You should use strlen here and not sizeof.
2021-12-20 05:04 PM
Thankyou for the reply I have not added the two function and now i added it and also checked it is working fine. Thankyou
HAL_UART_Transmit(&huart1,Buf, sizeof(Buf), 100);
You should use strlen here and not sizeof.
Thakyou i will change it.
2021-12-20 05:14 PM
As tdk said check the two option in the mcu settings.
2021-12-20 05:21 PM
And take a note that 3.3 is of a double type, not float. If you want it to be of a float type, write 3.3f .