关于LE05串口回显
-
Diga 谢谢支持。回调函数里没有成功触发过UART_EVENT_TIMEOUT,可以提供一下具体用法吗?我在中断配置结构体对空闲中断进行使能了。即.idleErrorIntEnable=true,
①回调函数在接收到的字节数不满预期需接收的字节数时,只会触发UART_EVENT_ERROR事件,并且此时UART_DRV_GetReceiveStatus(INST_UART1, &g_rxRemainNum);获取到的剩余接收字节数是对的
void uart1_RX_Callback(void *uartState, uart_event_t event, void *userData) { (void)uartState; (void)userData; if (event == UART_EVENT_END_TRANSFER) { g_rxComplete = true; } else if (event == UART_EVENT_TIMEOUT) { UART_DRV_GetReceiveStatus(INST_UART1, &g_rxRemainNum); g_TimeoutFlag = true; } else { UART_DRV_GetReceiveStatus(INST_UART1, &g_rxRemainNum); PRINTF("Number of remaining received bytes is %d\r\n", g_rxRemainNum); PRINTF("event is %x\r\n",event); } }
②这是我设置超时值的写法,有问题吗?我这么写后回调函数都无法正确触发了
UART_Type *uartPtr; uint32_t ctrl1Value = uartPtr->CTRL1; // 清除IDLESZ位(18 - 16位) ctrl1Value &= ~(0x7 << 16); // 设置IDLESZ为011b(3) ctrl1Value |= (0x3 << 16); // 写回修改后的值到CTRL1寄存器 uartPtr->CTRL1 = ctrl1Value;
③以下是我的main.c
int main(void) { /* USER CODE BEGIN 1 */ status_t status = STATUS_SUCCESS; UART_Type *uartPtr; /* USER CODE END 1 */ Board_Init(); /* USER CODE BEGIN 2 */ PRINTF("Build %s %s\n", __DATE__, __TIME__); PRINTF("UART Idle Interrupt Demo!\r\n"); // 读取CTRL1寄存器的值 uint32_t ctrl1Value = uartPtr->CTRL1; // 清除IDLESZ位(18 - 16位) ctrl1Value &= ~(0x7 << 16); // 设置IDLESZ为011b(3) ctrl1Value |= (0x3 << 16); // 写回修改后的值到CTRL1寄存器 uartPtr->CTRL1 = ctrl1Value; UART_DRV_InstallRxCallback(INST_UART1, uart1_RX_Callback, NULL); UART_DRV_InstallTxCallback(INST_UART1, uart1_TX_Callback, NULL); while (1) { status |=UART_DRV_ReceiveData(INST_UART1, g_RecData, UART_TX_RX_SIZE); /* Wait for reception to complete */ while ((!g_rxComplete) && (!g_TimeoutFlag)) ; if (g_TimeoutFlag) { PRINTF("Number of remaining received bytes is %d\r\n", g_rxRemainNum); } if (g_rxComplete) { UART_DRV_GetReceiveStatus(INST_UART1, &g_rxRemainNum); } status |=UART_DRV_SendData(INST_UART1, g_RecData,UART_TX_RX_SIZE - g_rxRemainNum); while (!g_txComplete) ; PRINTF("\r\n"); g_rxComplete = false; g_txComplete = false; g_TimeoutFlag = false; if (status != STATUS_SUCCESS) { break; } } PRINTF("UART Idle Interrupt Demo End!\r\n"); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
发帖前请查看
帮助没办法联网的电脑使用YCT
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...