Problem trying HID Read/Write Example

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
dadoubou
Posts: 22
Joined: 09 Jan 2013 23:16

Problem trying HID Read/Write Example

#1 Post by dadoubou » 12 Jan 2013 13:19

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)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Problem trying HID Read/Write Example

#2 Post by filip » 14 Jan 2013 15:42

Hi,

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

Regards,
Filip.

dadoubou
Posts: 22
Joined: 09 Jan 2013 23:16

Re: Problem trying HID Read/Write Example

#3 Post by dadoubou » 14 Jan 2013 19:01

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...

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Problem trying HID Read/Write Example

#4 Post by filip » 15 Jan 2013 09:53

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.

dadoubou
Posts: 22
Joined: 09 Jan 2013 23:16

Re: Problem trying HID Read/Write Example

#5 Post by dadoubou » 22 Jan 2013 14:52

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

dadoubou
Posts: 22
Joined: 09 Jan 2013 23:16

Re: Problem trying HID Read/Write Example

#6 Post by dadoubou » 22 Jan 2013 15:38

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 !

dadoubou
Posts: 22
Joined: 09 Jan 2013 23:16

Re: Problem trying HID Read/Write Example

#7 Post by dadoubou » 23 Jan 2013 13:16

After some tries, It seems that it also works with the '64's...

Strange behaviors those PICs ^^

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: Problem trying HID Read/Write Example

#8 Post by p.erasmus » 23 Jan 2013 13:28

I would think its more the case of strange compilers and users not strange PIC's :wink:
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Problem trying HID Read/Write Example

#9 Post by Dany » 23 Jan 2013 19:20

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...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroC PRO for PIC General”