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.

CCS10 MSP430F149 printf函数重定向到串口1,无法打印出整型数

Other Parts Discussed in Thread: MSP430F149, MSP430F5529

CCS版本: Version: 10.3.0.00007 

芯片型号:MSP430F149(没有使用TI的开发板)

烧录工具:MSP-FET430UIF

串口1:初始化程序参考官方例程fet_uart11_0115k_2

printf重定向程序:

/*
 * 函数名:Uart1_SendByte
 * 函数功能:串口1发送单个字符
 * 形参:data:要发送的字符数据
 * 返回值:无
 * 备注:无
 * */
void Uart1_SendByte(uint8_t data)
{
    while(!(IFG2 & UTXIFG1));
    TXBUF1 = data;
}

/*
 *
 * */
void Uart1_SendString(uint8_t* p)
{
    while(*p != '\0')
    {
        Uart1_SendByte(*p++);
    }
}

/*printf重定向到串口1*/
int fputc(int ch, FILE *f)
{
    Uart1_SendString((uint8_t*)&ch);
    return ch;
}

打印测试函数:

	uint8_t cnt = 0;
        while(1)
	{
	    if(cnt++ >= 255)
	    {
	        cnt = 0;
	    }
	    printf("cnt = %d\r\n",cnt);
	    delay_ms(1000);
	}

打印结果:

只能输出cnt=,字符输出没有问题,整型输出没有任何东西。

请问这种问题有什么办法可以解决吗?

  • 请问您的printf_support配置是什么? 

  • 选择的是full

  • 抱歉,之前漏掉了您第一条回复。我会在明天拿板子看一下后给您回复
  • 好的,我贴一下我的串口1初始化的具体代码给您

    /*
     * 函数名:Uart1_Init
     * 函数功能:初始化串口1,P3.6-TX,P3.7-RX 波特率115200 8N1
     * 形参:无
     * 返回值:无
     * 备注:该串口用于调试信息输出
     * */
    void Uart1_Init(void)
    {
        volatile unsigned int i;
    
        P3SEL |= 0xC0;                            // P3.6,7 = USART1 option select
        BCSCTL1 &= ~XT2OFF;                       // XT2on
    
        do
        {
            IFG1 &= ~OFIFG;                           // Clear OSCFault flag
            for (i = 0xFF; i > 0; i--);               // Time for flag to set
        }
        while ((IFG1 & OFIFG));                   // OSCFault flag still set?
    
        BCSCTL2 |= SELM_2 + SELS;                 // MCLK= SMCLK= XT2 (safe)
    
        ME2 |= UTXE1 + URXE1;                     // Enable USART1 TXD/RXD
        UCTL1 |= CHAR;                            // 8-bit character
        UTCTL1 |= SSEL1;                          // UCLK = SMCLK
        UBR01 = 0x45;                             // 8Mhz/115200 - 69.44
        UBR11 = 0x00;                             //
        UMCTL1 = 0x00;                            // modulation
        UCTL1 &= ~SWRST;                          // Initialize USART state machine
    //    IE2 |= URXIE1;                            // Enable USART1 RX interrupt
    }

  • 好的 谢谢您的反馈,我会在确认后给您回复

  • 您好,请问有什么进展了吗?

  • 抱歉,回复有些晚了

    我使用的时MSP430F5529(手边没有149的板子)

    是可以正常打印的 

    相关设置如下

  • 您好,我不是用ccs的终端显示打印数据,我用的是电脑的串口工具,通过串口1重定向printf函数来打印。请问这两者有什么区别吗?

    我尝试了您的建议,但是还是不行。

  • 抱歉,之前漏掉了您的回复,您现在问题解决了没有?

    我不是用ccs的终端显示打印数据,我用的是电脑的串口工具,通过串口1重定向printf函数来打印。请问这两者有什么区别吗?

    CCS打印的话,使用的是开发板上的虚拟串口来打印的

  • 不好意思回复晚了,串口输出整型数和浮点数还是不行,我现在暂时在输出前把整型数或浮点数转换成字符串,再用%s输出到串口工具就可以显示了。