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

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jump to solution
1,303 Views
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 Solution
189 Views
chandrasekarkan
Contributor III

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

View solution in original post

0 Kudos
3 Replies
189 Views
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

190 Views
chandrasekarkan
Contributor III

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

View solution in original post

0 Kudos
189 Views
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