Receiving data using UART

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Receiving data using UART

ソリューションへジャンプ
2,648件の閲覧回数
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,155件の閲覧回数
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,156件の閲覧回数
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,155件の閲覧回数
matthewkendall
Contributor V

fgetc is non-blocking:

int c;

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

    /* do something with (char)c */

}

0 件の賞賛
返信
2,155件の閲覧回数
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,155件の閲覧回数
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,155件の閲覧回数
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,154件の閲覧回数
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 件の賞賛
返信