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.
工具与软件:
我正在使用此 TMDSCNCD263板、这是 IO 扩展器 TMDSHSECDOCK。
我的项目有一个要求、例如需要在 UART 上提供输入、然后我必须在同一 UART 上接收该输入数据、之后我需要使用 UART FIFO 传输接收到的该数据、在一些延迟之后、我必须读取 UART FIFO 并在控制台上打印。 我的数据是64字节
以下是我的代码
#包含
#包含
#include "ti_drivers_config.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"
#包含
#define APP_UART_BUFSIZE (200U)
#define APP_UART_RECEIVE_BUFSIZE (64U)
uint8_t gUartBuffer[APP_UART_BUFSIZE];
uint8_t gUartReceiveBuffer[APP_UART_RECEIVE_BUFSIZE];
Volatile uint32_t gNumBytesRead = 0u、gNumBytesWritten = 0u;
#define APP_UART_ASSERT_ON_FAILURE (transferOK、事务)\
执行{\
if ((SystemP_SUCCESS!=(transferOK))||(UART_TRANSMIT_STATUS_SUCCESS!= TRANSACTION_STATUS))\
{\
DebugP_assert (false);/* UART TX/RX 失败!! */\
}\
} while (0)
void delay_ms (int 毫秒)
{
clock_t start_time = clock ();
while (clock ()< start_time +毫秒*(Clocks_per_SEC / 1000));
}
void uart_echo (void * args)
{
int32_t transferOK;
UART_Transaction 传输;
drivers_open();
Board_driversOpen();
DebugP_log ("[UART] Echo example started ...\r\n");
UART_Transaction_init (&trans);
/*发送输入字符串*/
gNumBytesWritten = 0u;
trans.buf =&gUartBuffer[0U];
strncpy (((char *) tran.buf、"这是 UART 回波测试阻塞模式\r\n 请输入64字节...\r\n、APP_UART_BUFSIZE);
tran.count = strlen ((char *) tran.buf);
transferOK = UART_WRITE (gUartHandle[CONFIG_UART_CONSOLE]、&Trans);
APP_UART_ASSERT_ON_FAILURE (transferOK、TRANS);
/*从 UART 控制台读取64个字节*/
gNumBytesRead = 0u;
TRANS.buf =&gUartReceiveBuffer[0U];
TRANS.COUNT = APP_UART_RECEIVE_BUFSIZE;
transferOK = UART_read (gUartHandle[CONFIG_UART_CONSOLE]、&trans);
APP_UART_ASSERT_ON_FAILURE (transferOK、TRANS);
gNumBytesRead = TRANS.count;
/*将接收到的数据传回*/
DebugP_log ("将%d 字节传回:%.*s\r\n"、gNumBytesRead、gNumBytesRead、gUartReceiveBuffer);
gNumBytesWritten = 0u;
TRANS.buf =&gUartReceiveBuffer[0U];
tran.count = gNumBytesRead;
transferOK = UART_WRITE (gUartHandle[CONFIG_UART_CONSOLE]、&Trans);
如果(transferOK != SystemP_Success){
DebugP_log ("UART 写错误"发生!\r\n);
}其他{
DebugP_log ("Successfully transeled %d bytes\r\n"、gNumBytesRead);
}
APP_UART_ASSERT_ON_FAILURE (transferOK、TRANS);
/*短时间延迟以允许数据传输完成*/
ClockP_usleep (100000);
/*为回传数据准备缓冲区*/
gNumBytesRead = 0u;
TRANS.buf =&gUartReceiveBuffer[0U];
TRANS.COUNT = APP_UART_RECEIVE_BUFSIZE;//调整为预期的最大大小
/*读取回传数据*/
transferOK = UART_read (gUartHandle[CONFIG_UART_CONSOLE]、&trans);
如果(!transferOK){
DebugP_log ("UART 读取错误"发生!\r\n);
}其他{
gNumBytesRead = TRANS.count;
DebugP_log ("回显%d 字节:%.*s\r\n"、gNumBytesRead、gNumBytesRead、gUartReceiveBuffer);
}
/*发送退出字符串*/
DebugP_log ("所有测试均已通过!!\r\n ");
Board_driversClose ();
drivers_close();
}
我可以在 UART 上轻松接收输入数据、但我不确定是否使用 FIFO 在同一 UART 上接收数据、然后重新发送。 如果它使用 FIFO、我无法使用 FIFO 读回数据
在这方面有什么帮助吗?
您好、Swati、
我仔细阅读了您的代码、但我无法理解这里的确切问题是什么。 您能否简单地帮助我了解所面临的确切问题是什么?
此致、
Shaunak
尊敬的 Shaunak:
实际上、我需要检查 FIFO 以便在 UART 中发送和接收数据、为此、我首先要做的是在 UART 上发送数据、然后在同一 UART 上接收数据、但有一些延迟
您好、Swati、
我尝试了运行您的代码、并成功执行了:
1.写入"这是 UART 回波测试阻塞模式\r\n 请输入64个字节。" 使用 UART 写入的字符串
2.读取64字节输入
3.使用 UART 写操作将接收到的数据传回 UART、然后有100ms 的延迟
4.然后回读回传数据、我唯一更改的是最后一次 UART 读取中的错误检查、而不是
if (!transferOK) { DebugP_log("UART read error occurred!\r\n"); } else { gNumBytesRead = trans.count; DebugP_log("Echoed %d bytes: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer); }
I 使用
/* Read the echoed data */ transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &trans); APP_UART_ASSERT_ON_FAILURE(transferOK, trans); gNumBytesRead = trans.count; DebugP_log("Echoed %d bytes: %.*s\r\n", gNumBytesRead, gNumBytesRead, gUartReceiveBuffer);
我的控制台输出:
代码正常运行、UART FIFO 将用于 Tx 和 Rx、但我不确定具体是什么问题? 您所执行的第二次 UART 读取也通过 UART 控制台完成、用户将在其中输入数据。 在延迟后、是否要直接读取 UART FIFO 而不是从用户输入获得64B? 因为问题中上述代码将从用户而不是 FIFO 读取 UART 控制台输入。
请详细说明我的理解(以上4点)是否也是您正在努力实现的。
我可以从同一个 UART (本例中为64字节)进行写入和读取。
此致、
Shaunak
尊敬的 Shaunak:
昨天、我做了您建议的相同操作、而且我也成功完成了此测试。
感谢您的支持与时间
您好、Swati、
很高兴知道它起作用了!
谢谢、此致、
Shaunak