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版本: 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=,字符输出没有问题,整型输出没有任何东西。
请问这种问题有什么办法可以解决吗?
好的,我贴一下我的串口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 }
抱歉,之前漏掉了您的回复,您现在问题解决了没有?
我不是用ccs的终端显示打印数据,我用的是电脑的串口工具,通过串口1重定向printf函数来打印。请问这两者有什么区别吗?
CCS打印的话,使用的是开发板上的虚拟串口来打印的