Hi,
I created a project which receive and send the string through LPUART with my laptop. The LPUART_DRV_GetReceiveStatus() function always return STATUS_BUSY after rerceived the first string from my laptop. What wrong in my code ? Can I clear the Rx receive flag ?
My code below,
void Debug_HardwareInitialize(void)
{
/* Initialize LPUART instance */
LPUART_DRV_Init(INST_LPUART_1, &lpUartState1, &lpuart_1_InitConfig1);
/* Install the callback for rx events */
LPUART_DRV_InstallRxCallback(INST_LPUART_1, Debug_RxCallback, NULL);
DebugPrint("\rDebug Init Complete");
}
static void Debug_RxCallback(void *driverState, uart_event_t event, void *userData)
{
/* Unused parameters */
(void)driverState;
(void)userData;
/* Check the event type */
if(event == UART_EVENT_RX_FULL)
{
/* The reception stops when newline is received or the buffer is full */
if((Debug.RxBuffer[Debug.RxCounter] != '\0') && (Debug.RxBuffer[Debug.RxCounter] != CTRL_C) && (Debug.RxBuffer[Debug.RxCounter] != LF) && (Debug.RxBuffer[Debug.RxCounter] != CR) && (Debug.RxCounter != (DEBUG_BUFFER_LEN - 2U)))
{
/* Update the Buffer index and the RxBuffer */
Debug.RxCounter++;
LPUART_DRV_SetRxBuffer(INST_LPUART_1, (uint8_t *)&Debug.RxBuffer[Debug.RxCounter], 1U);
}
}
}
void Debug_Process(void)
{
LPUART_DRV_ReceiveData(INST_LPUART_1, (uint8_t *)Debug.RxBuffer, 1U);
/* Wait for transfer to be completed */
while(LPUART_DRV_GetReceiveStatus(INST_LPUART_1, &bytesRemaining) == STATUS_BUSY);
status = LPUART_DRV_GetReceiveStatus(INST_LPUART_1, &bytesRemaining);
if(status != STATUS_SUCCESS)
{
DebugPrint("\rCOM: An error occurred! The application will stop!");
}
Debug.RxCounter++;
Debug.RxBuffer[Debug.RxCounter] = 0U;
DebugPrint("\rCOM: %s", Debug.RxBuffer);
Debug.RxCounter = 0;
memset(Debug.RxBuffer, 0, sizeof(Debug.RxBuffer));
}
Anyone know how to fix this problem ? Please support me.
Thanks