USBUART component: When continuously sending data to the host and the host port is connected but not open, the PSoC5 application will hang.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

I've developed code that uses the recommended while((USBUART_CDCIsReady()) == 0){} before sending new data to the host.

All is working great if the host is connected and the port is open.  As soon as a close the host port, eventually the PSoC app code hangs on the while() statement shown above.

Is there a proper way to detect if the port is open to accept new data?

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
1 Solution

Ekta,

Thank you.  You method works if you have implemented a non-blocking task structure.

As it turns out, I've created a routine that works in a blocking mode or non-blocking mode depending on which you select.

See this link for the solution: PSoC5LP : USBUART component detects port close

The solution uses the SysTick timer @ 1ms to detect if the host is non-responsive within less than 2ms.  If non-responsive, the routine kicks out and drops the transmitted bytes just as it would if it were a true UART.

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
2 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello Len,

As per my understanding you need to check when the Port is open in order to receive data, meanwhile you do not want the code to be suck in the while loop so as to carry on other functionalities.

In such a case you can try setting a flag inside the an if condition such as:

if (USBUART_CDCIsReady==0)

{

flag =1;

}

else

{

flag=0;

}

You  need to check for this flag before transmitting any data and transmit the data only if the flag is set to 0.

This will prevent the code from getting stuck in a loop.

Please feel free to correct me if my understanding is not clear.

Also could you provide more details about your application?

Best Regards

Ekta

0 Likes

Ekta,

Thank you.  You method works if you have implemented a non-blocking task structure.

As it turns out, I've created a routine that works in a blocking mode or non-blocking mode depending on which you select.

See this link for the solution: PSoC5LP : USBUART component detects port close

The solution uses the SysTick timer @ 1ms to detect if the host is non-responsive within less than 2ms.  If non-responsive, the routine kicks out and drops the transmitted bytes just as it would if it were a true UART.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes