I can receive data with usb but i can't send data from pc

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

cross mob
lock attach
Attachments are accessible only for community members.
anil_sun
Level 2
Level 2
First solution authored 10 replies posted 10 sign-ins

Hello,

I'm trying to stream data with usbart in my project. Since I'm new, there were mistakes in some places that I couldn't understand.
When I try to send data directly from the main while coding, I can see the data from the termite program properly. However, when I ask the PC to enter and send a data, I cannot receive any data from the termite. (Also, while the program I am trying to get data from by selecting mode is installed on the card, I get the USB corrupted warning in windows.)
If I tell about the data selection with the mode, I am sending data in the form of "T:0,S:100,V0:-0.1,V1:0.1" over the computer. The variable "T:0" here is set to be used to select the mode. When you use it in this way, the data does not come and the termite freezes. Where could I have made a mistake?
Also, I'm not sure about the driver, because I have arduino installed on my computer, when I connect the card to the computer, it shows up as "USB Serial Device" in the device manager. and as i said it works when i try to print data inside without getting data. I leave the project file below.

0 Likes
1 Solution

Hey Len (@Len_CONSULTRON ),

Thank you for help me. I have now solved my problem.
count=USBUART_1_GetCount();
uint8 data[count];
USBUART_1_GetData(data,count);
By correcting the code like this, I get the data correctly and I can process this data.

There is one more thing I want to ask you in addition. When I plug it into the computer, the process happens, but when I plug it into the phone for testing, unfortunately the application crashes. Is there anything else I need to do for the phone?

View solution in original post

0 Likes
10 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

@anil_sun ,

I've downloaded your project.

I have no issue getting your data from the PSoC to the PC.

Is the issue you are having with sending data from the PC to the PSoC?

If so, you have no code on the PSoC to receive PC data or do anything with it.

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

If you remove the comment lines in the coding, it becomes a code that can send data from the computer. Please uncomment the comments and try to run the program again. My problem is that I can't send the data "T:0,S:100,V0:-0.1,V1:0.1" via termite and get the requested data. I couldn't solve the problem here.

0 Likes

@anil_sun ,

Are you using the debugging features of the PSoC Creator IDE?

When I execute your project I get the following WITHOUT entering "T:0,S:100,V0:-0.1,V1:0.1":

First pass

Debug watches after the ReceiveUART()/SplitReceivedBuffer() line:

Len_CONSULTRON_0-1686239168646.png

Termite then displays a new index of data_ch[][] every 10ms.  Good so far.

Second pass

Debug watches after the ReceiveUART()/SplitReceivedBuffer() line:

Len_CONSULTRON_2-1686239393835.png

Termite then displays a new index of data_ch[][] every 10ms.  Again good so far.

Third pass

Debug watches after the ReceiveUART()/SplitReceivedBuffer() line:

Len_CONSULTRON_3-1686239656926.png

Termite then displays a new index of data_cv[][] every 0ms.  Data displayed but too fast???  Scanrate = 0.  Is this your intent?

Fourth pass

Debug watches after the ReceiveUART()/SplitReceivedBuffer() line:

Len_CONSULTRON_4-1686239879060.png

NOTHING is displayed in Termite.

Additionally the checkuart variable gets cleared (set to 0) in 

        if(checkuart==1)
        {
            ReceiveUART();
            checkuart=0;
        }

Therefore the ReceiveUART() no longer gets run to be able to read data from the PC.

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

Hi,

As you said, I re-examined the code in debug mode. I was trying to communicate with uart before, "dataReceived[bufferindex]=rxdata;" The function was working fine, but now that it is usb, meaningless data is written to the "dataReceived" array via rxdata. Hence "potValues.scanrate=atoi(dataReceiveHolder.S);
delaytime=1000/(potValues.scanrate/1);" cannot be calculated properly. So "delaytime" seems to be 0ms. This is not what I want.

How can I fix the data coming via USB and prevent the PC from sending a value without entering a value? Can you help me on this issue? What should I do, change the card design or add or remove something extra in the coding?

0 Likes

@anil_sun ,

I will continue to take a look at it.

However, what I wanted to point out is that after it reached the Fourth Pass, your code stopped looking for new incoming data because checkuart remains 0 and doesn't get set to 1.

I've used the USBUART often and I found that receiving data has no issue.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

@Len_CONSULTRON 

First of all, Len, it's been a real pleasure working with you. I'm trying it with you and I made a small change in the coding. Looking at his current work, he doesn't do anything without typing. But this time, there is the following situation, I have to send the value "T:0,S:100,V0:-0.1,V1:0.1" 24 times. When I send it 24 times, it splits it correctly and the code starts working. Do you know any method? In addition, I solved the usb error I mentioned above, there was a small short circuit on the card. After fixing this short circuit, the problem went away.

0 Likes

@anil_sun ,

I see from your new project you added a new conditional:

 

        if(0!=USBUART_1_DataIsReady())
        {
            uint8 rxdata=USBUART_1_GetChar();
            if(rxdata)
        ...
        }

 

with  USBUART_1_DataIsReady().  Good idea.

Sadly the USBUART API calls are not fully equivalent to the UART API calls.

For example, the _GetChar() API call has some caveats.  Here is the note in the USBUART datasheet for this call:

uint8 USBUART_GetChar(void)
Description:
This function reads 1-byte data packet from the buffer. This function must not be called if more than 1 byte is received, because call of this function for more than 1 byte received case could lead to unpredicted results. Use USBUART_GetCount() API to get number of received bytes.

Parameters:
   None

Return Value:
  uint8: Received one character

Side Effects:
  None

The function USBUART_GetChar() description comment lists:

This function reads one byte of received data from the buffer. If more than one byte has been received from the host, the rest of the data will be lost.

With Termite, you enter the data on the PC on a separate field.  When you select "ENTER", the entire line is sent.   This could be a problem with _GetChar()

I recommend reading all the Rx data into a buffer as an interrupt.   When you execute the ReceiveUART() you then use the buffered Rx data.

I also recommend using count=USBUART_GetCount() and USBUART_GetData(&ptr2buffer, count) to move the Rx data to the buffer.

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

Hey Len (@Len_CONSULTRON ),

Thank you for help me. I have now solved my problem.
count=USBUART_1_GetCount();
uint8 data[count];
USBUART_1_GetData(data,count);
By correcting the code like this, I get the data correctly and I can process this data.

There is one more thing I want to ask you in addition. When I plug it into the computer, the process happens, but when I plug it into the phone for testing, unfortunately the application crashes. Is there anything else I need to do for the phone?

0 Likes

@anil_sun ,

I'm happy to hear the USBUART_1_GetCount() and USBUART_1_GetData() combination works.

...

 

There is one more thing I want to ask you in addition. When I plug it into the computer, the process happens, but when I plug it into the phone for testing, unfortunately the application crashes. Is there anything else I need to do for the phone?


I have no clue.   Sorry.  Maybe someone with more phone UART experience can provide good information.

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

@Len_CONSULTRON 

Does anyone in this form know about this topic? If so can you tag it?

I think the "usb-serial-for-android" library is used on the application side. So why I can't communicate. Or we can't add the necessary driver on the phone?

0 Likes