Easy HID

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Easy HID

Post by richardb » Fri Feb 22, 2013 9:31 am

Hi i thought it was about time i tried using USB HID comms as the usb cdc has various issues for what i'm doing.

i've tried generating the files with the Easy HID add on and it finds the device, the add new hardware wizard pops up i click to install but it says hannot start the hardware(code 10).
i'm actually using a 18f2553 and i've tried compiling for a 2553 and for a 2550 but it makes no difference.

i've added

const
TXReportRAM = TX_REPORT_RAM,
RXReportRAM = RX_REPORT_RAM

as jerry suggested to let it compile.

i left the settings to default in easy hid.



any ideas?
Hmmm..

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Feb 22, 2013 4:05 pm

Code 10 looks like a windows driver problem, looking at this:

http://pcsupport.about.com/od/findbyerr ... -error.htm

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Feb 22, 2013 11:33 pm

I think you'll get that one if you're not servicing the USB often/fast enough, too.

When it first starts up and begins to enumerate, you pretty much can't do anything else until that completes. At that point, you have to be able to get and service the packets at about 100us intervals.

Once that dance is over, then you have a bit more leeway.

Are you using polling or interrupts? If you post your main program, perhaps we can see what the issue might be.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Mon Feb 25, 2013 8:48 am

Hi,


Thanks for the replys,

it seems the code that i used from the easy hid plugin is the problem

Code: Select all

{
*****************************************************************************
*  Name    : USBPROJECT.BAS                                                 *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 22/02/2013                                                     *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}

// device and clock...                                                                                                                                                                                                                                         
Device = 18F2553
Clock = 48
   
// 20Mhz crystal, 48Mhz internal (FS USB)
Config
   PLLDIV = 5,
   CPUDIV = OSC1_PLL2,
   USBDIV = 2,
   FOSC = HSPLL_HS,
   VREGEN = ON

// this is the programs descriptor, generated by EasyHID - you
// can find it in the same folder as this program...
#option USB_DESCRIPTOR = "USBProjectDesc.bas"

// import the HID module...
Include "usbhid.bas"
 Const
    TXReportRAM = TX_REPORT_RAM,
    RXReportRAM = RX_REPORT_RAM


// an example TX report structure, which contains a message
// string and two word values - the variable TXReport will overlay
// the structure over the USB dual port RAM buffer...
Structure TTXReport
   Message As String
   ValueA As Word
   ValueB As Word
End Structure
Dim TXReport As TTXReport Absolute TXReportRAM  

// an example RX report structure, which contains some bit
// value and a configuration byte - the variable RXReport will overlay
// the structure over the USB dual port RAM buffer...
Structure TRXReport
   LED0 As Bit
   LED1 As Bit
   Configuration As Byte
End Structure    
Dim RXReport As TRXReport Absolute RXReportRAM

// rather than using the above structures, you can read and write data
// directly into a buffer array - choose which method you prefer - examples
// are given in the main program block...
Dim Buffer(32) As Byte

// connect to USB...
Repeat
Until Attached

// the main program loop shows two different ways in which you can read and
// write HID data. The ReadReport() and WriteReport() techniques are very useful
// when sending and receiving highly structured data (for example, string, bits,
// words etc). If you just want to send and receive blocks of bytes, then
// ReadArray() and WriteArray() are probably more useful - you can of course
// use both ways!
While true
   
   // this is one way you can read some HID data...
   If DataAvailable Then
      ReadReport
      // the data is now in our RX structure - for example, PORTD.0 = RXReport.LED0 etc...
      // Alternatively, you can access the buffer directly as an array. For example,
      // HID.RXReport(0), HID.RXReport(1)...
   EndIf

   // rather than using ReadReport(), as shown above, you can read data directly 
   // into a buffer array. For example,
   If DataAvailable Then
      ReadArray(Buffer,10)
   EndIf

   // this is one way you can write some HID data...
   TXReport.Message = "Hello World"
   TXReport.ValueA = $1234
   TXReport.ValueB = $0000
   WriteReport
   
   // rather than using WriteReport(), as shown above, you can write data directly
   // into a buffer array. For example,
   Buffer(0) = 0
   Buffer(1) = 1
   WriteArray(Buffer,2)
Wend
this doesnt work, but the sample within the sf directory seems to work ok


I now have another hid problem at the pc end but i think i should ask this in a seperate thread
Hmmm..

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Mon Feb 25, 2013 9:50 am

ok...if i comment out

Code: Select all



WriteArray(Buffer,2) 


Then it works
Hmmm..

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Mon Feb 25, 2013 12:41 pm

What sort of data rates can you get from the pic to the pc with HID?
I was getting a max of 30kilo Bytes per second with cdc.

this method seems slow but i havent done a full test maybe 100 records a second with the text display commented out (i'm using ihid by graham it uses "mcHID.dll" )
Hmmm..

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Feb 25, 2013 1:03 pm

Depends the descriptor of course, but a theoretical maximum of 64KB. In reality, it will be less than that - depends on what the MCU is having to do, USB loading etc. However, from my experiences with HID, it is generally a lot faster than CDC.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Post by richardb » Mon Feb 25, 2013 4:05 pm

Thanks for your help,


i think i'll retry doing this from scratch as somethings obviously not correct.
Hmmm..

Post Reply