工具/软件:
您好:
我 使用 UART 作为回调、并通过串行接口使用 python 脚本获取数据。 数据不会被读入、而 是直接进入 Error_PolicyMin 中。
有人能解释为什么吗?
C 代码:
/*
*========= callbackFxn ========
*通过 UART 读取数据时调用函数
*/
void callbackFxn (UART2_handle handle、void *缓冲器、size_t 计数、
void *userArg、int_fast16_t 状态)
{
IF (STATUS!= UART2_STATUS_SUCCESS)
{
/* UART2_READ()中出现 RX 错误*/
printf ("UART RX error:%d\n"、status);
}
numBytesRead = count;//读取字节数
SEM_POST (&SEM_UART);// Erhöht 信标 um 1 -> Anderer Thread darf weiterarbeiten
}
/*
*========= UART_MAIN ========
*/
void *MAIN_UART (void *arg0)
{
uint8_t buffer[uart_buffer_size];/* UART 缓冲区*/
UART2_Handle UART;
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;
/*调用驱动程序初始化函数*/
gpio_init ();
/*创建信标、0表示信标已锁定*/
semStatus = SEM_INIT (&SEM_UART、0、0);
printf ("semStatus error:%d\n"、semStatus);
if (semStatus!= 0)
{
/*创建信标时出错*/
printf ("semStatus error:%d\n"、semStatus);
}
/*在回调读取模式下创建 UART */
UART2_Params_init (&uartParams);
uartParams.readMode = UART2_Mode_callback;
uartParams.readCallback = callbackFxn;
uartParams.baudrate = 115200;
UART = UART2_OPEN (CONFIG_UART2_0、&uartParams);
IF (UART = NULL)
{
/* UART2_OPEN ()失败*/
printf ("UART_open 错误:%d\n"、UART);
}
/*循环永久回显*/
while (1)
{
numBytesRead = 0;
printf ("vor UART Read");
/*为 bytesRead 传递 NULL、因为它未在本示例中使用*/
STATUS = UART2_READ (UART、缓冲器、sizeof (缓冲器)、NULL);// UART 配置为回调->如果读取完成、则调用 callbackFxn
printf ("每个 UART 读取");
IF (STATUS!= UART2_STATUS_SUCCESS)
{
/* UART2_READ()失败*/
printf ("UART RX error:%d\n"、status);
}
printf ("vor SEM_WAIT");
/*等待 UART-READ 回调(callbackFxn)执行并释放 SEM_UART*/
SEM_WAIT (&SEM_UART);//