Code example for UART receive?  ReceiveDataBlocking, or with a callback function?

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

Code example for UART receive?  ReceiveDataBlocking, or with a callback function?

1,933 Views
johnbeale
Contributor II

I am using Kinetis Design Studio 3.0.0 on Win7 and my target is Kinetis MKL16Z32VFT4.  I have lpsciCom1 / UART0 set up through Processor Expert, I am using 256000 baud 8/N/1 and the UART transmit side works fine with such commands as:

 

  LPSCI_DRV_SendDataBlocking(FSL_LPSCICOM1, outString, length, 50);  // port, buffer, # bytes, timeout

 

I am having trouble with understanding how the UART Receive function should work.  For example, if I do

  status = LPSCI_DRV_ReceiveDataBlocking(FSL_LPSCICOM1, rxString, 2, 50);  // receive serial data from external control device

 

the return 'status' value is always 0, regardless if anything was received or not. How do I know how many bytes have been received, if any?

 

I gather there is way to receive data using a callback function, but I have been unable to find any simple examples of such code. I have a very simple application, without any RTOS.

Labels (1)
0 Kudos
4 Replies

1,232 Views
johnbeale
Contributor II

I have another device transmitting  a long string of characters to my device, but I never receive more than one character at a time and I get the "timeout" flag 0x0C. Maybe I don't have an interrupt turned on? I don't know if this is the right place to post a code example, but I would benefit from some kind of tutorial or example code showing a working UART in receive mode.  Is there anything online like that?

0 Kudos

1,232 Views
neoxiong
NXP Employee
NXP Employee

The blocking receving is done by checking a sync flag set (or a semaphore in RTOS environment) with a timeout para. A background interrupt works with UART controller to try to receive the exact number of bytes you speicifed through API LPSCI_DRV_ReceiveDataBlocking(), when all bytes are received, the call return kStatus_LPSCI_Success. If Timeout is reached, the call return kStatus_LPSCI_Timeout. So there is no situation when this function get data less than you want. Only two results.

I can't understand your case about "Before I may have been receiving the tail end of my previous transmission (RS-422 half-duplex circuit gives me a built-in loopback)", could you explain more?

In a common case, uart receive interrupt should be enabled always to prevent when peer send data out and uart receive is disabled.

1,232 Views
johnbeale
Contributor II

On further investigation, I have seen a value of

  kStatus_LPSCI_Timeout = 0x0C 

returned from the Rx call when there was no data.  Before I may have been receiving the tail end of my previous transmission (RS-422 half-duplex circuit gives me a built-in loopback).

0 Kudos

1,232 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello John,

So do you still have any question ?

BR

Alice

0 Kudos