PICPLC16 v6 on discount
It is currently 20 Sep 2014 01:10

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 12 Jan 2013 13:19 
Offline

Joined: 09 Jan 2013 23:16
Posts: 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 :

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)


Top
 Profile  
 
PostPosted: 14 Jan 2013 15:42 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 7752
Hi,

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

Regards,
Filip.


Top
 Profile  
 
PostPosted: 14 Jan 2013 19:01 
Offline

Joined: 09 Jan 2013 23:16
Posts: 19
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...


Top
 Profile  
 
PostPosted: 15 Jan 2013 09:53 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 7752
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.


Top
 Profile  
 
PostPosted: 22 Jan 2013 14:52 
Offline

Joined: 09 Jan 2013 23:16
Posts: 19
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


Top
 Profile  
 
PostPosted: 22 Jan 2013 15:38 
Offline

Joined: 09 Jan 2013 23:16
Posts: 19
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 :

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 !


Top
 Profile  
 
PostPosted: 23 Jan 2013 13:16 
Offline

Joined: 09 Jan 2013 23:16
Posts: 19
After some tries, It seems that it also works with the '64's...

Strange behaviors those PICs ^^


Top
 Profile  
 
PostPosted: 23 Jan 2013 13:28 
Offline

Joined: 05 Mar 2009 10:28
Posts: 3085
I would think its more the case of strange compilers and users not strange PIC's :wink:

_________________
P.Erasmus
Saratov,Russia
--------------------------------------------------------------


Top
 Profile  
 
PostPosted: 23 Jan 2013 19:20 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3276
Location: Nieuwpoort, Belgium
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.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group