[技术问答] MA35D1 RTP printf float問題

[复制链接]
 楼主| 发表于 2024-5-14 15:44 | 显示全部楼层 |阅读模式
手册中有提到M4具有浮点数的支援,我想要利用printf打印出float的数值,UART却没有办法显示该数值。
以下是我用Template测试的代码,想请问要如何正确打印出float值呢?

感谢回覆

#include <stdio.h>
#include "NuMicro.h"


void SYS_Init(void)
{

    /* Enable UART module clock */
    CLK_EnableModuleClock(UART16_MODULE);

    /* Select UART module clock source as HXT and UART module clock divider as 1 */
    CLK_SetModuleClock(UART16_MODULE, CLK_CLKSEL3_UART16SEL_HXT, CLK_CLKDIV3_UART16(1));

    /* Set GPD multi-function pins for UART16 RXD and TXD */
    SYS->GPD_MFPH &= ~(SYS_GPD_MFPH_PD10MFP_Msk | SYS_GPD_MFPH_PD11MFP_Msk);
    SYS->GPD_MFPH |= SYS_GPD_MFPH_PD10MFP_UART16_RXD | SYS_GPD_MFPH_PD11MFP_UART16_TXD;

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and CyclesPerUs automatically. */
    SystemCoreClockUpdate();
}

/* Main */
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, IP clock and multi-function I/O. */
    SYS_Init();

    /* Init UART to 115200-8n1 for print message */
    UART_Open(UART16, 115200);

    float test = 1.5;
    printf("test = %f\n", test);

    return 0;
}
发表于 2024-6-7 17:40 | 显示全部楼层
请参考牛卧堂上相同的问题回复
发表于 2024-8-20 19:06 | 显示全部楼层
一楼在这里在回复一下不是更好
您需要登录后才可以回帖 登录 | 注册

本版积分规则

485

主题

3270

帖子

4

粉丝
快速回复 返回顶部 返回列表