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/EK-LM4F120XL:将浮点值打印到 UART 时出现问题!

Guru**** 2465890 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/663530/ccs-ek-lm4f120xl-problems-printing-floats-to-the-uart

器件型号:EK-LM4F120XL

工具/软件:Code Composer Studio

您好!  

我一直在开发一个信号采集程序、用于计算 RMS 值、频率等。 它一直工作正常、但我在尝试将浮点值打印到 UART 时遇到问题、如图所示。 我正确地配置了 UART、因为 UART 确实会打印整数。 我已经在论坛和 TI wiki 上阅读了有关--printf_support 的内容,并且还将其设置为 full,但我不知道这在讨论 UART 打印时是否有用。 可以有人帮助吗?

此致、Tales Duque。

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

    您好 Tales、

    我们的传感器集线器示例提供了几种转换浮点值以进行 UART 打印的方法。 我将发布其中一个:

    //
    //以浮点格式获取最新数据的本地副本。
    //
    TMP006DataTemperatureGetFloat (&g_sTMP006Inst、&fAmbient、&fObject);
    
    //
    //将浮点环境温度转换为整数部分
    //和分次器件,便于打印。
    //
    i32IntegerPart =(int32_t) fAmbient;
    i32FractionPart =(int32_t)(fAmbient * 1000.0f);
    i32FractionPart = i32FractionPart -(i32IntegerPart * 1000);
    if (i32FractionPart < 0)
    {
    i32FractionPart *=-1;
    }
    UARTprintf ("环境%3d.%03d\t"、i32IntegerPart、i32FractionPart);
    
    //
    //将浮点环境温度转换为整数部分
    //和分次器件,便于打印。
    //
    i32IntegerPart =(int32_t) fObject;
    i32FractionPart =(int32_t)(fObject * 1000.0f);
    i32FractionPart = i32FractionPart -(i32IntegerPart * 1000);
    if (i32FractionPart < 0)
    {
    i32FractionPart *=-1;
    }
    UARTprintf ("对象%3d.%03d\n"、i32IntegerPart、i32FractionPart); 

    此主题还提供了一些有关打印浮点值的建议: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/313525/1090648#1090648

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我看到你在那里做了什么、非常有趣! 感谢您的回复、帮助了我一群人!

    故事。