USB HID device not detected

microchipmicrocontrollerpicusb

I'm making a USB HID device using PIC18F2550 using 20 MHz crystal input and using the MikroC PRO C compiler for PIC.

These are my configuration settings:

Enter image description here

unsigned char readbuff[64] absolute 0x500;
unsigned char writebuff[64] absolute 0x540;
char cnt;
char kk;

void interrupt() {
    USB_Interrupt_Proc();
}

void main()
{
    TRISA = 0;
    ADCON1  |= 0x0f;
    CMCON   |= 7;
    HID_Enable(&readbuff, &writebuff);
    while(1)
    {
        /*
            LATA=0;
            delay_ms(200);
            LATA=0xFF;
            delay_ms(200);
        */

        while(!HID_Read())
            ;

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

        while(!HID_Write(&writebuff, 64))
            ;
    }
}

Also included in the project is the file USBdesc.c which can be generated inside the HID terminal of MikroC. But the device is not detected at all…

[UPDATE]

I've tried the older version on MikroC, that is, version 8.2, and I got it working (the HID device gets detected.). But I still can't make it work with the MikroC PRO.

PS.: To make sure the microcontroller is working fine, I loaded a sample hex file for a USB HID mouse onto the microcontroller, and it was working. I just can't figure out what's wrong with my code…

Best Answer

I have made a data acquisition device using PIC18F2550 using MikroC PRO. It seems your configuration is OK. But there are another things to consider. You must insert a 1 kohm resistor between D+ and VCC. Otherwise the PC can not detect it as a high-speed device.

Another important thing is to add a capacitor (10 µf or something like this, electrolytic) to the VUSB pin which is pin number 14 of PIC18F2550. I was in problem for a long period only for this issue. Disable the USB voltage regulator, and then make a trial. You can see this tutorial; it might help.

I don't know whether your device is bus-powered or self-powered. You must declare it in file USBdsc.c:

const char USB_SELF_POWER = 0x80; //When it is bus powered

If your device is self-powered then replace it with

const char USB_SELF_POWER = 0xC0; //When it is self powered

An HID device can operate in two modes, interrupt or polling. From your code, you are using the interrupt method. You must declare it in USBdsc.c by the code

const char USB_TRANSFER_TYPE = 0x03; //0x03 is for interrupt

Enter image description here

Attach the USBDsc.c file to your project. Sometimes it is created by the USB HID Terminal Tool, but not attached - make sure that your USBDsc.c is attached.