8 Replies Latest reply on Oct 15, 2015 3:50 AM by user_1377889

    Problem with USB HID

    sven.tiebel

      Hello,

         

      sorry for my english. I'm using the USB HID Example AN82072 with some changes. I change this to a 64 bit data performance. It works. But when i add some code in the program loop, i cant receive data from the PC. Send to PC is ok. I think is timing problem, but what can i do? Here is a little piece of the code.

         

       

         

       for(;;)
          {

         

          if(USBFS_GetEPState(IN_ENDPOINT) == USBFS_IN_BUFFER_EMPTY)
                  {
                     
                      /* Load data located in IN_Data_Buffer and load it into the IN endpoint */
                      USBFS_LoadInEP(IN_ENDPOINT, IN_Data_Buffer, MAX_NUM_BYTES);
                      /* Enable the OUT endpoint to recieve data */
                      USBFS_EnableOutEP(OUT_ENDPOINT);
                  }    
                  
                  /* Check to see if the OUT Endpoint is full from a recieved transaction. */
              if(USBFS_GetEPState(OUT_ENDPOINT) == USBFS_OUT_BUFFER_FULL)
              {
                  /* Get the number of bytes recieved */
                  Byte_Count = USBFS_GetEPCount(OUT_ENDPOINT);
                  /* Read the OUT endpoint and store data in OUT_Data_Buffer */
                  USBFS_ReadOutEP(OUT_ENDPOINT, OUT_Data_Buffer, Byte_Count);
                  /* Re-enable OUT endpoint */
                  USBFS_EnableOutEP(OUT_ENDPOINT);
              }

               
              temperature = MeasureThermoCoupleTemp();

         

       

         

      }

         

       

         

      With this code "temperature = MeasureThermoCoupleTemp();" it doesn't work. Without this code i can receive data from PC.

         

      Thanks

         

      Sven

        • 1. Re: Problem with USB HID
          user_1377889

          Welcome in the forum, Sven.

             

          It is always advisable to post your complete project, so that we all can have a look at all of your settings. To do so, use
          Creator->File->Create Workspace Bundle (minimal)
          and attach the resulting file. With the few information I cannot see an issue.

             

           

             

          Bob

             

          PS: I am located near Bremen, where do you live?

          • 2. Re: Problem with USB HID
            sven.tiebel

            Hello Bob,

               

            thanks for your welcome. I am in the near Nürnberg. Far away from you. I found more about my problem. When the time between the checks "USB OutBuffer full" is to long (more then 5ms) the data from PC will not received or ignored. Time is less then 5ms data received. I set in the USBFS element in the Endpoint descriptors the intervall time higher. No effect. More "USB OutBuffer full"  request in the loop, then it's ok, data received. I post my test program. I hope, you can help me.

               

            Thanks and regards

               

            Sven

            • 3. Re: Problem with USB HID
              user_1377889

              You should remove all your delays and move your Process_EP2() into the preceding if-clause just below the copy of the data into your buffer and the re-enabling of the out-EP.

                 

               

                 

              Bob

                 

              PS: So we presumably will meet in February 2016 when visiting the "embedded world" faire at Nürnberg (Nuremberg)

              • 4. Re: Problem with USB HID
                sven.tiebel

                Thanks for help, Bob. Maybe we will meet on the "embedded". The delays are a  replacement for other code. Normally the loop time is about 80ms. And then i don't receive data from the host. That's my problem, long program loop time.

                   

                Thanks

                   

                Sven

                • 5. Re: Problem with USB HID
                  user_1377889

                  The data from host is captured automatically, but you look into your buffer even when it is not filled because nothing was received yet.

                     

                  The receiving code part is in an "if"-clause which is not executed when there is no data yet. If you use a while-clause you can be sure that you did received data.

                     

                  A way out could be to enable the interrupts for your USBFS component and insert in USBFS_episr.c near line 155 some (keep it short!) code to indicate data was received.

                     

                   

                     

                  Bob

                  • 6. Re: Problem with USB HID
                    sven.tiebel

                    The hint with the interrupt was good. Works fine.

                       

                    Thanks

                    1 of 1 people found this helpful
                    • 7. Re: Problem with USB HID
                      user_1377889

                      Glad to have been of some help!

                         

                       

                         

                      Bob

                      • 8. Re: Problem with USB HID
                        mike.strauser

                        Bob,

                           

                        I have a similar issue.  I cloned the code from AN82072 and then modified it.  The way the code was originally written the check for IN data happens very often (in the Main infinite loop).  I only need to send data to the Host very infrequently - actually I have a master slave relationship with the PC software - it asks for data and I send it, but again the PC software only asks infrequently.  What I found is that if I fill the IN endpoint less often then 10ms, I lose the ability to send data to the PC and the PC software that came with AN82072 crashes.

                           

                        I thought it might be tied to the interval in the IN Endpoint but changing that to a higher value (100ms) didn't help either.  What determines how often the IN Endpoint has to be filled?  Why does this work this way?

                           

                        Mike.