USBUART hangs when PC not get the data.

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

cross mob
Anonymous
Not applicable

Hello,

   

I want to put some debug Messages to the PC, but when the PC not connected the Program hangs in the 'while':

   

        while (USBUART_CDCIsReady() == 0u); // wait until buffer clear
        USBUART_PutString(txData);

   

Any solution to get information that PC is ready to receive data?

   

Regards,

   

Michael

0 Likes
5 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Have you made the variable Volatile that is inportant.  Please post your code. 

   

Syntax

   

To declare a variable volatile, include the keyword volatile before or after the data type in the variable definition. For instance both of these declarations will declare foo to be a volatile integer:

   

volatile int foo;
int volatile foo;

   

Now, it turns out that pointers to volatile variables are very common. Both of these declarations declare foo to be a pointer to a volatile integer:

   

volatile int * foo;
int volatile * foo;

   

Volatile pointers to non-volatile variables are very rare (I think I've used them once), but I'd better go ahead and give you the syntax:

   

int * volatile foo;

   

And just for completeness, if you really must have a volatile pointer to a volatile variable, then:

0 Likes
Anonymous
Not applicable

This all are Cypress API Funcioins (USBUART). 

   

Problem is when MCU first sends Data it goes into the USBTXBuffer, but when no PC connected the Data stays in the Buffer, next Time when the MCU sends the next data it will be hangs by "wait until buffer clear".

   

 

   

So I need a Solution to find out if a PC is connected and ready to receive or not...

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Put a counter into the while-loop and break out when waiting too long.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Yes but this slows the system when no PC is connected, no other was to detect if a PC is ready to receive? Like DTR or something 

0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Those options will not be possible with USBUART I guess, unless you change code in Kitprog.

0 Likes