How to receive data of varying length over UART?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to receive data of varying length over UART?

Jump to solution
1,417 Views
Adarshnanda
Contributor II

Hey !

I am using s32k144 evaluation board, and I was using the UART_PAL library for receiving the data over UART using the MODBUS protocol. I used thenon blocking uart_receivedata() API in the while loop and was using the callback to check for the receive event and receive the data. 

Things worked until I was certain about the length of data to be received, but when the length of data to be received is not fixed and varies time to time, what I am supposed to do?

I saw a number of threads of the same, but none of the threads provides with an absolute solution, I request you to please guide me with a proper solution, if possible, provide a piece of code/screenshot of the same.

I have attached a screenshot, and here the length of data to be received is uncertain in different cases, inside the switch statement.

Adarshnanda_0-1683700959540.png

Please guide us with a solution @Robin_Shen 

 

Regards,

Adarsh.

 

 

0 Kudos
Reply
1 Solution
1,356 Views
Adarshnanda
Contributor II

Hey @Robin_Shen ,

I checked out the thread and it worked for me. The only confusing part is , the thread has some answers related to receiving data through DMA and some with respect to receiving data via Interrupts.

Let me just summarize the steps to follow, who want to implement UART_IDLE_LINE_RECEIVE using INTERRUPTS. 

Please note that we need to add inside the LPUART drivers.

1. In LPUART_DRV_INIT function, you have to configure the peripheral registers to enable the IDLE LINE INTERRUPT & set the number of idle characters to be received before the IDLE flag is set. You should look at the reference manual for that. I have configured it for 8 idle characters & I am attaching the screenshot here.

Adarshnanda_0-1684475336590.png

 

2. Inside the LPUART_DRV_IRQHandler, you have to check whether the IDLE_LINE_DETECT flag is set or not & if it is then call the function LPUART_DRV_RxIdleCallback(It is not there by default, user needs to define this) . Please note - This Function needs to be called at the starting of the IRQ_Handler.

Adarshnanda_1-1684475537665.png

3. In the file - (callbacks.h) , inside the enum - uart_event_t, define an event UART_EVENT_IDLE_DETECT.

Adarshnanda_2-1684475649321.png

 

4. Define the LPUART_DRV_RxIdleCallback & provide a function prototype of the same.

Adarshnanda_3-1684475819016.png

5. After this, you can use it in your application.

Adarshnanda_4-1684475984634.png

Thanks @Robin_Shen & I hope that this is helpful for others.

 

Regards,

Adarsh.

 

View solution in original post

3 Replies
814 Views
khalid11
Contributor I

HI

I AM TRYING TO RECEIVE DATA THROUGH UART IN LPC804, and using mcuxpresso ide can anyone plz provide me the code and tell me the steps to receive the data.

0 Kudos
Reply
1,402 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Adarsh,

Sorry the idle detection is not implemented within recent S32K1 SDK/RTD drivers. Have you refer to the discussion in S32K144 LPUART IDLE Line Interrupt Configuration ?  You need to change the SDK drivers in order to get  LPUART idle line interrupt.


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

1,357 Views
Adarshnanda
Contributor II

Hey @Robin_Shen ,

I checked out the thread and it worked for me. The only confusing part is , the thread has some answers related to receiving data through DMA and some with respect to receiving data via Interrupts.

Let me just summarize the steps to follow, who want to implement UART_IDLE_LINE_RECEIVE using INTERRUPTS. 

Please note that we need to add inside the LPUART drivers.

1. In LPUART_DRV_INIT function, you have to configure the peripheral registers to enable the IDLE LINE INTERRUPT & set the number of idle characters to be received before the IDLE flag is set. You should look at the reference manual for that. I have configured it for 8 idle characters & I am attaching the screenshot here.

Adarshnanda_0-1684475336590.png

 

2. Inside the LPUART_DRV_IRQHandler, you have to check whether the IDLE_LINE_DETECT flag is set or not & if it is then call the function LPUART_DRV_RxIdleCallback(It is not there by default, user needs to define this) . Please note - This Function needs to be called at the starting of the IRQ_Handler.

Adarshnanda_1-1684475537665.png

3. In the file - (callbacks.h) , inside the enum - uart_event_t, define an event UART_EVENT_IDLE_DETECT.

Adarshnanda_2-1684475649321.png

 

4. Define the LPUART_DRV_RxIdleCallback & provide a function prototype of the same.

Adarshnanda_3-1684475819016.png

5. After this, you can use it in your application.

Adarshnanda_4-1684475984634.png

Thanks @Robin_Shen & I hope that this is helpful for others.

 

Regards,

Adarsh.