hello,
i see there is lpuart_echo_s32k144 demo, the rx using LPUART_DRV_InstallRxCallback(INST_LPUART_LPUART_1, rxCallback, NULL);
why still in polling mode the receive the data in main loop?
how to modify it with rx only interrupt mode ?
if remove below code
/* Receive and store data byte by byte until new line character is received,
* or the buffer becomes full (256 characters received)
*/
LPUART_DRV_ReceiveData(INST_LPUART_LPUART_1, buffer, 1U);
/* Wait for transfer to be completed */
while(LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining) == STATUS_BUSY);
/* Check the status */
status = LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining);
it doesn't work.
int main(void)
{
/* Write your local variable definition here */
status_t status;
/* Declare a buffer used to store the received data */
uint32_t bytesRemaining;
/* Write your code here */
/* For example: for(;;) { } */
/* Initialize and configure clocks
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
/* Initialize LPUART instance */
LPUART_DRV_Init(INST_LPUART_LPUART_1, &lpUartState1, &lpUartInitConfig1);
/* Install the callback for rx events */
LPUART_DRV_InstallRxCallback(INST_LPUART_LPUART_1, rxCallback, NULL);
/* Send a welcome message */
LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);
/* Infinite loop:
* - Receive data from user
* - Echo the received data back
*/
while (1)
{
/* Receive and store data byte by byte until new line character is received,
* or the buffer becomes full (256 characters received)
*/
LPUART_DRV_ReceiveData(INST_LPUART_LPUART_1, buffer, 1U);
/* Wait for transfer to be completed */
while(LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining) == STATUS_BUSY);
/* Check the status */
status = LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining);
if (status != STATUS_SUCCESS)
{
/* If an error occurred, send the error message and exit the loop */
LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)errorMsg, strlen(errorMsg), TIMEOUT);
break;
}
/* Append string terminator to the received data */
bufferIdx++;
buffer[bufferIdx] = 0U;
/* If the received string is "Hello Board", send back "Hello World" */
if(strcmp((char *)buffer, "Hello Board\n") == 0)
{
strcpy((char *)buffer, "Hello World\n");
}
/* Send the received data back */
LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, buffer, bufferIdx, TIMEOUT);
/* Reset the buffer index to start a new reception */
bufferIdx = 0U;
}
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Hi @alice_th,
Even if you configure interrupts for the UART module, you still need to signal that a reception is going to happen.
You must call LPUART_DRV_ReceiveData(). And upon reception, either use LPUART_DRV_SetRxBuffer() to update the buffer and have a continuous reception or end the reception and call LPUART_DRV_ReceiveData() again to enable the Rx interrupt, all inside the UART callback function.
I've attached a modified main for the lpuart_echo example where the polling section in main is removed, and the callback handling I mentioned is implemented. The echo is only performed if bRxFlag is set, which happens in the UART_EVENT_RX_FULL event.
Hope this helps.
i only need rx as interrupt and tx use as printf no need interrupt