usb HID keyboard continues typing

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

cross mob
Anonymous
Not applicable

Hello everybody

   

            I am trying a keyboard HID interfacing with Android device. I have implemented all the things as per given in an example project. I am using psoc 3.

   

            I am sending some digits to android device on receiving particular no of interrupts, and then an Enter.

   

My problem is continues typing of one of the digit that I am sending to receiver device.

   

I mean after hundred times correct working if I send 00326598 then sometimes it will continuously type 000…..0s on that device. I guess it is hanging because it is not getting proper acknowledgement time to time.

   

            Have you gone through any acknowledgement problem from Android device.

   

Is my guess is true? What can be the solution?

0 Likes
7 Replies
Anonymous
Not applicable

Hey,

   

please upload your project files so that we could help you further. ]

   

 

   

Regards,

   

kmmankad

0 Likes
Anonymous
Not applicable

 Did you try connecting your Keyboard to your PC to see if it gets binded to the standard HID driver and check if you are able to receive the keys properly on a Notepad?

   

Isolate your problem to check if it is a board issue or some Android issue.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

yes i have tried by connecting with pc. There is no problem for configuring as hid keyboard. and its working nice without hanging.

   

Then why is it hanging with Android.

   

at the time of waiting for ackngemnt ; if it doesn't come in time the Android device shows continuously typing of one of the character that the PSoC(Keyboard) had sent before hanging.

   

for temporary solution i use to stop and start the USB . thus its working fine but i need to remove this reinitializing of USB and i have to work with Android device only.

   

i have attached my project. Please go through the same.

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

I cannot see any error so far, but as I'm known to be someone who strongly criticizes code readability I'll have my two cents on your programming as well:

   

Keep in mind, that a program is read by us humans MANY times before it is released, so to put an emphasis on readability will save you time, money and disappointings.

   

You are excessively using global variables instead of locals. Even loop-variables (i) are declared globally which is against all rules of programming and marked as error in some compilers (rightfully). From the point of readability, global vars are declared far away from their usage within the program while local vars are more near-by and as such better remembered. Probably you think that due to the register structure of the 8051 this would be better (yes, I admit it will produce more dense code), but I would suggest to spare that for time- or space-critical program parts only.

   

Your indentation could be enhanced.

   

A note on comments: I've found authors that suggest to use NO COMMENTS AT ALL (at least because they are written early and changed last to reflect the actual state of the program). I'm not as radical, but I suggest to comment a single line that needs a comment by writing the text indented AFTER the code. This gives the reader the choice to read the code OR the comment, your style with code- and comment-lines forces the reader to read BOTH.

   

 

   

When reading this it looks a bit harsh, but I assure you it is not ment that way at all. Indeed my intention is to give you an insight into "Clean Code" (google for that) and all its advantages.

   

 

   

Happy coding

   

Bob 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I am a C learner as well, this might be of help in the globals vs locals discussion ( I will know what

   

Bob knows in about 50 years) -

   

 

   

http://en.wikipedia.org/wiki/Global_variable

   

 

   

A thread of performance impact of using locals -

   

 

   

http://cboard.cprogramming.com/cplusplus-programming/28355-global-vs-local-variables.html

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

thanks for your reply Bob,I will improve my way of coding.
your suggestions will help me allot to get along.Actually the code was from my practice workspace.

anyway the project i have uploaded was with resetting USB component. So it will reinitialize after not getting acknowledgement from android device.
if we remove this reinitializing then it will hang there forever and android device will show like keypad is typing a character continuously.[Is it looking for a break code? if so how to send it?]
if you make the following curly braces of while loop empty then you may get the error

    USBFS_1_LoadInEP(1, Keyboard_Data, 8);
    /*Waits for ACK from PC*/
    while(!USBFS_1_bGetEPAckState(1))
    {

        wait++;
        if(wait>40000)
        {
            USBFS_1_Stop();
            for(time2start=0; time2start>10000; time2start++);
            /*Start USBFS Operation and Device 0 and with 5V operation*/
            USBFS_1_Start(0, USBFS_1_DWR_VDDD_OPERATION);
            /*Enables OUT EP*/
            USBFS_1_EnableOutEP(2);
            /*Waits for USB to enumerate*/
            while(!USBFS_1_bGetConfiguration());         
            /*Begins USB Traffic*/
            USBFS_1_LoadInEP(1, Keyboard_Data, 8);
            for(time2start=0; time2start>10000; time2start++);
            time2start=5555;
            break;
        }
    }
    wait=0;
    /*Advances to the next ASCII Character*/
    i++;   

   

one more thing , I have not get the error yet with Windows devices, so please try on Android.

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

Fine that you took my writing as an advice!

   

Sorry, not beeing able to test your configuration because I do not own any android-device to connect with, but your description lets me think whether you are barking at the right tree: Probably there might be an error on the android side.

   

 

   

Bob

0 Likes