PSOC5 USB UART buffer when no program is reading the data

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

cross mob
Anonymous
Not applicable

Good evening. I have a test project running on CY8CKIT_059 that uses both the USB UART and the UART (Kitprog port). The protocol used by both ports is configurable.

I am able to read data from PSOC on the two ports at the same time with two PUTTY sessions. Problem is that when I turn off the session reading from USB COM port, the other port will halt sending commands.

This is because I write to both ports, and on USB side there's the 'classic' cycle that waits the USB to be ready for transfer:

while (0u == USBCOM_CDCIsReady());

USBCOM_PutString(s); 

This does not happen on the serial port.

What's the best strategy to detect full buffer (or better COM port not open by any program/not active)? Also is there a way to detect port reopening as to suspend send and clear the buffers befrore restarting the serial stream?

Thanks

Marco

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Marco,

try to put expiration counter before PutString. It no connection it simply skips sending data until re-connected

void DisplayData(void) // output to terminal

{

    sprintf(buff, ".... \r\n", ....); // your data

   

    uint16 ctr = 0;

    while(USBUART_1_CDCIsReady() == 0u) {ctr++;  if (ctr > 400) return; } // prevent buffer overflow if COM stopped

    //USBUART_Check_CDC_Init(); //check if USBUART initialized

   

    USBUART_1_PutString(buff);              // Send data to PC

}

View solution in original post

3 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Marco,

try to put expiration counter before PutString. It no connection it simply skips sending data until re-connected

void DisplayData(void) // output to terminal

{

    sprintf(buff, ".... \r\n", ....); // your data

   

    uint16 ctr = 0;

    while(USBUART_1_CDCIsReady() == 0u) {ctr++;  if (ctr > 400) return; } // prevent buffer overflow if COM stopped

    //USBUART_Check_CDC_Init(); //check if USBUART initialized

   

    USBUART_1_PutString(buff);              // Send data to PC

}

Anonymous
Not applicable

Thanks for your answer. This is similar to my first logic 'always try to send'. I thought about some event/status that could directly tell this situation of USB non used/read by the computer. This is to avoid a useless loop. By the way, where does 400 come from? Any timing logic behind (clock/datarate)? Also could be implemented with a variable length wait (if last send was successful, try hard, otherwise skip earlier)

Bye

Marco

0 Likes

Marco,

I don't have better solution. The 400 was empirically deducted, I believe that 200 was not enough when I used it.

/odissey1

0 Likes