cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

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
Reply
5 Replies
rola_264706
Honored Contributor II

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
Reply
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
Reply
JoMe_264151
Expert II

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

   

 

   

Bob

0 Likes
Reply
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
Reply
Vasanth
Moderator
Moderator

Hi,

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

0 Likes
Reply