This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430FR5994:在 float 的 sprintf 之后发送 UART 数据

Guru**** 2589300 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/715681/ccs-msp430fr5994-sending-uart-data-after-sprintf-of-float

器件型号:MSP430FR5994

工具/软件:Code Composer Studio

您好!

我将在 sprintf 之后发送浮点值。 分辨率正在显著降低。 附加了代码片段。 请帮我解决问题。

浮点温度= 56.32562435245;
字符串 Temp[80];
sprintf (stringTemp、"%f"、temp);


unsigned int len;
len = strlen (stringTemp);

for (i=0;<len; i++){
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = stringTemp[i];
} 

此致、

Prudhvi Sagar

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我刚才用谷歌搜索"sprintf 默认浮点格式"、第一个参考显示(关于"%f"):

    "如果缺少精度,则输出6位数字;"

    可能尝试"%15.11f"或其他操作。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Prudhvi Sagar 说:
    float temp = 56.3252435245;

    以及 Bruce 对 sprintf 格式字符串的评论,32位 float 大约有 7.2个十进制数字。

    而64位双精度型大约有15.9个十进制数字。 因此、还应考虑将 temp 变量更改为 double 类型。