Receiving data using UART

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

Receiving data using UART

Jump to solution
1,272 Views
andreeaignat
Contributor I

Hello.

I am using a K60D100M tower system with MQX4.0.2. I have successfully sent data using UART3 and am now trying to receive data. I have tried using fread() and _io_read() in order to do so and the data transfer works, but both functions block the task until data is received. Is there a way to receive data without blocking the task while waiting for it?

Tags (1)
0 Kudos
1 Solution
779 Views
soledad
NXP Employee
NXP Employee

Hi Andreea,

In addition please check the below thread.

Serial IO_SERIAL_NON_BLOCKING flag


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
6 Replies
780 Views
soledad
NXP Employee
NXP Employee

Hi Andreea,

In addition please check the below thread.

Serial IO_SERIAL_NON_BLOCKING flag


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
779 Views
matthewkendall
Contributor V

fgetc is non-blocking:

int c;

while ((c = fgetc(fp)) != -1) {

    /* do something with (char)c */

}

0 Kudos
779 Views
matthewkendall
Contributor V

Actually, I should clarify that a bit. Both fgetc() and fread() are blocking or non-blocking depending on how you open the port.

fp = fopen("ittyc:", (pointer)(IO_SERIAL_NON_BLOCKING));

The IO_SERIAL_NON_BLOCKING flag is explained in the MQX I/O Drivers User's Guide, which is in ...\Freescale\Freescale_MQX_4_0\doc\mqx\MQXIOUG.pdf

779 Views
andreeaignat
Contributor I

I have tried opening the port with IO_SERIAL_NON_BLOCKING, but the task is still blocked if no data is received. Do you have any other suggestions?

0 Kudos
779 Views
matthewkendall
Contributor V

Opening it with the IO_SERIAL_NON_BLOCKING flag works for me. I am using the interrupt-driver version of the driver but I don't know if that makes a difference; I wouldn't think so. Do you have any other flags set on the port; hardware handshaking for example? I wonder if that could cause it to block.

If nothing is obvious I would suggest using the debugger to pause execution at a time when you think it is blocked and seeing where that thread is (presumably somewhere down in the driver). If it is not clear how it got there run it again with a breakpoint on the fgetc() call then step into it to see why it blocks.

778 Views
mjbcswitzerland
Specialist V

Hi Andreea

I recommend posting in the MQX forum since the issue is related to the use of MQX SW rather than the Kinetis itself.

Regards

Mark

0 Kudos