请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LAUNCHXL-F2800137工具/软件:
我正在 LAUNCHXL-F2800137 上测试 SCI 通信。
我注意到当使用 printf () 语句时,它会影响程序的执行方式。
包含以下 printf() 语句将阻止 SCI_readCharBlockingFIFO() 读取更多字符。
if( xMBPortSerialInit( 0, 115200, 8, MB_PAR_NONE ) == FALSE )
{
printf("error: com init failed");
}
else
{
/* Enable the transmitter. */
vMBPortSerialEnable( TRUE, FALSE);
//Block Execution
for (;;)
{
uint16_t receivedChar = SCI_readCharBlockingFIFO(SCIA_BASE);
uint16_t rxStatus = SCI_getRxStatus(SCIA_BASE);
if((rxStatus & SCI_RXSTATUS_ERROR) != 0)
{
//
//If Execution stops here there is some error
//Analyze SCI_getRxStatus() API return value
//
ESTOP0;
}
printf("%c\n", receivedChar);
SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar);
}
}
当计算机发送“123"时“时、带有 printf() 语句的 SCI_writeCharBlockingFIFO() 将在 1ò 处停止。
删除 printf() 语句将允许代码按预期运行。
if( xMBPortSerialInit( 0, 115200, 8, MB_PAR_NONE ) == FALSE )
{
printf("error: com init failed");
}
else
{
/* Enable the transmitter. */
vMBPortSerialEnable( TRUE, FALSE);
//Block Execution
for (;;)
{
uint16_t receivedChar = SCI_readCharBlockingFIFO(SCIA_BASE);
uint16_t rxStatus = SCI_getRxStatus(SCIA_BASE);
if((rxStatus & SCI_RXSTATUS_ERROR) != 0)
{
//
//If Execution stops here there is some error
//Analyze SCI_getRxStatus() API return value
//
ESTOP0;
}
//printf("%c\n", receivedChar);
SCI_writeCharBlockingFIFO(SCIA_BASE, receivedChar);
//fflush(stdout);
}
}
删除 printf () 语句将允许在发送“123"时“时回显“123"。“。
为什么 printf () 会影响执行?
谢谢、
Allan