Receiving data using UART

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Receiving data using UART

跳至解决方案
2,641 次查看
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?

标记 (1)
0 项奖励
回复
1 解答
2,148 次查看
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 项奖励
回复
6 回复数
2,149 次查看
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 项奖励
回复
2,148 次查看
matthewkendall
Contributor V

fgetc is non-blocking:

int c;

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

    /* do something with (char)c */

}

0 项奖励
回复
2,148 次查看
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

2,148 次查看
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 项奖励
回复
2,148 次查看
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.

2,147 次查看
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 项奖励
回复