Page 1 of 1

Problem trying HID Read/Write Example

Posted: 12 Jan 2013 13:19
by dadoubou
Hi !

As a beginner with PIC HID communication, I started by trying the HID Read-Write Example of MikroC's (4.60) help.

So... It works... but only one time !

Some explainations :

I send a character ('8' for example) using HID Terminal, so I see the PIC immediately responds something like:
0x38, 0x00, 0x00, 0x00, 0x00 [...]

So I try with another character ('A' for example), and I got no answer from the PIC on the HID terminal.

Then, I can try to send anything, the HID Terminal crashes (button 'Send' remains pushed and nothing happens, I can't click anywhere...). Until y reset the PIC, if I try restarting the HID Terminal, my PIC which was seen as a "My PIC Device" as I called it, gets named "Device VID=1234 PID=0001"...

As I can handle a bit C# programming, I made a program to use the HID communication with the PIC, but same problem: first sending : OK, second sending : OK but no answer, and third sending : my application crashes.

I'm using a 18F2450, and the example I use is this one :

Code: Select all

unsigned char readbuff[64] absolute 0x500;   // Buffers should be in USB RAM, please consult datasheet
unsigned char writebuff[64] absolute 0x540;

char cnt;
char kk;

void interrupt(){
   USB_Interrupt_Proc();                   // USB servicing is done inside the interrupt
}

void main(void){
  ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  CMCON  |= 7;                            // Disable comparators

  HID_Enable(&readbuff,&writebuff);       // Enable HID communication

  while(1){
    while(!HID_Read())
      ;

    for(cnt=0;cnt<64;cnt++)
      writebuff[cnt]=readbuff[cnt];

    while(!HID_Write(&writebuff,64))
      ;
  }
}
Does someone experienced this problem ? Do you know how can I solve it ?

Thanks in advance,
dadoubou


(I'm French and I hope my English is not too bad)

Re: Problem trying HID Read/Write Example

Posted: 14 Jan 2013 15:42
by filip
Hi,

Please, can you use the USB example given in the compiler Examples folder and see if this happens also ?

Regards,
Filip.

Re: Problem trying HID Read/Write Example

Posted: 14 Jan 2013 19:01
by dadoubou
Thanks filip,

I just tried with the HID_Read_Write_Interrupt.mcppi Example : it does the same...
I don't know where does the problem come from, maybe the HID Windows Driver ? USB Library maybe ?

Here's a screenshot of the projet settings (I'm using a 18F2450, not a 4450) :

Image

Hope you could do something for me...

dadoubou

Edit : I have a 18F4450 so I tried with it and it works perfectly, but still not with my 18F2450...

Re: Problem trying HID Read/Write Example

Posted: 15 Jan 2013 09:53
by filip
Hi,

Are you sure that you have placed the read and write buffers on the correct locations in USB RAM ?

I see that they are placed on the 0x500 and 0x540 addresses respectively in your code.
These addresses are valid for 18F4550, but for 18F2450 I think they should be 0x480 and 0x488, because the USB RAM is just 16 bytes (please consult the datasheet).

Also, the USB Descriptor file has to be changed, HID_INPUT_REPORT_BYTES and HID_OUTPUT_REPORT_BYTES constants should be 8 bytes, not 64.

Regards,
Filip.

Re: Problem trying HID Read/Write Example

Posted: 22 Jan 2013 14:52
by dadoubou
Hi !

Thanks for your answer, I tried it, modifying the adresses and the report bytes, but still does the same...
Another idea ?

I don't know why but it works perfectly with a 18F4550...

Regards,
dadoubou

Re: Problem trying HID Read/Write Example

Posted: 22 Jan 2013 15:38
by dadoubou
Problem seems to be solved !

I just replaced each '64' with an '8' in the example and in the 'USBdc.c', and I set 480h to 488h for the USB RAM adresses.
So the example looks like this to work with a 18F2450 :

Code: Select all

unsigned char readbuff[8] absolute 0x480;   // Buffers should be in USB RAM, please consult datasheet
unsigned char writebuff[8] absolute 0x488;

char cnt;
char kk;

void interrupt(){
   USB_Interrupt_Proc();                   // USB servicing is done inside the interrupt
}

void main(void){
  ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  //CMCON  |= 7;                            // Disable comparators

  HID_Enable(&readbuff,&writebuff);       // Enable HID communication

  while(1){
    while(!HID_Read())
      ;

    for(cnt=0;cnt<8;cnt++)
      writebuff[cnt]=readbuff[cnt];

    while(!HID_Write(&writebuff,8))
      ;
  }
}
And it seems to work perfectly for me, hope It will help someone else ;-)
(don't forget to change the two '64' into two '8' in the usbdsc.c)

See you !

Re: Problem trying HID Read/Write Example

Posted: 23 Jan 2013 13:16
by dadoubou
After some tries, It seems that it also works with the '64's...

Strange behaviors those PICs ^^

Re: Problem trying HID Read/Write Example

Posted: 23 Jan 2013 13:28
by p.erasmus
I would think its more the case of strange compilers and users not strange PIC's :wink:

Re: Problem trying HID Read/Write Example

Posted: 23 Jan 2013 19:20
by Dany
dadoubou wrote:After some tries, It seems that it also works with the '64's...
Strange behaviors those PICs ^^
If you are using 64 then the buffer addresses $480 and/or $488 are wrong, they are only 8 bytes apart, so something will be messed up...