non-blocking write and read, writes and reads respectively only the first character of the string (Txed or Rxed)

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

non-blocking write and read, writes and reads respectively only the first character of the string (Txed or Rxed)

跳至解决方案
2,831 次查看
chandrasekarkan
Contributor III

Tower K60.

I have fisrt installed uart2 from user_config.h so init_bsp.c installs UART2 at this line...

_kuart_polled_install("ttyc:", &_bsp_sci2_init, _bsp_sci2_init.QUEUE_SIZE);

then opened it with "myapp.c"

MQX_FILE_PTR fPtr = fopen("ttyc:", NULL);

int uartparam = 0 | IO_SERIAL_NON_BLOCKING | IO_SERIAL_TRANSLATION;

ioctl( fPtr, IO_SET_SERIAL_FLAGS, &uartparam);

write(fPtr, "HELLO", 5); writes only the first character 'H'.

and

read(fPtr, rdBuffer, 16); reads only the first character sent from hyperterminal on PC.


What should I do to write a whole string and read a whole string in non-blocking mode?

1 解答
1,717 次查看
chandrasekarkan
Contributor III

Enabled "ITTYC" in user_config.h and changed fopen("ttyc:", NULL) to fopen("ittyc", NULL)... this did the trick for me...

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,717 次查看
DavidS
NXP Employee
NXP Employee

Hi Chandrasekar,

When you set the UART to polled mode the UART QUEUE is not used.  It is only used in interrupt (i.e. ittyc) mode.

If you keep driver in polled mode, then you need to use the fstatus(fPTR); call to determine if a character is present and ready to get.  If it returns non-zero then you have a character waiting.  If zero no character waiting.

If that doesn't work for you please try the interrupt mode.

Regards,

David

1,718 次查看
chandrasekarkan
Contributor III

Enabled "ITTYC" in user_config.h and changed fopen("ttyc:", NULL) to fopen("ittyc", NULL)... this did the trick for me...

0 项奖励
回复
1,717 次查看
BielikM
Contributor III

Hi,

You installed polled uart and tried to write data in non blocking mode. It is wrong combination. On k70 uart module is no internal buffer. Your application is faster than uart baudrate. When second byte wants to be send, first byte is still sending and non blocking write returns 1 (1 byte successfully sent). It is not a mistake, it is normal non blocking behavior.

Your solution with iTTYC (interrupt TTYC) should  be correct.

In general with non blocking mode you should always check return values from read() or write() functions.

Regards,

Martin