CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18f4550 Usb Hid Device Problem [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

18f4550 Usb Hid Device Problem [Solved]
PostPosted: Sun Dec 18, 2016 6:16 pm     Reply with quote

EDIT: IN FACT IT WAS NOT A PROBLEM. I SUPPOSED THAT MY DEVICE WILL BE SEEN IN THE DEVICE MANAGER WITH ITS NAME. BUT, IT DOESN'T SEEN. SO, IT IS NOT A PROBLEM. THE DEVICE IS SUCCESSFULLY COMMUNICATING WITH MY PC. IT LOOKS AS A "HID DEVICE" AND PROJECT WIZARD WORKS PROPERLY.


Hello everyone,

I am studying the USB protocol and I need to implement some device classes. I implemented a cdc and bulk device with 18f4550 using project wizard. There are OK and run properly. Bu I can't run hid device. I created it with project wizard, neither polling method nor interrupt method don't work. I plug my pic to usb and in device manager I saw a USB device under HID Devices and I hear "da da" windows plug sound. I tried to update driver of it but it did not change. My codes are below and also I attached my hex file. If anyone can try it I will be very happy. I think, the last option is maybe Windows 10.

header file:
Code:

#include <18F4550.h>
#device ADC=10

#FUSES NOWDT,PLL5,HSPLL                    //No Watch Dog Timer

#use delay(clock=48MHz,crystal=20MHz,USB_FULL)

#define USB_ISR_POLLING
#define USB_CONFIG_VID 0x0461
#define USB_CONFIG_PID 0x0020
#define USB_CONFIG_BUS_POWER 100
#define USB_STRINGS_OVERWRITTEN

char USB_STRING_DESC_OFFSET[]={0,4,26};

char const USB_STRING_DESC[]={
   //string 0 - language
      4,  //length of string index
      0x03,  //descriptor type (STRING)
      0x09,0x04,  //Microsoft Defined for US-English
   //string 1 - manufacturer
      22,  //length of string index
      0x03,  //descriptor type (STRING)
      'U',0,
      'S',0,
      'B',0,
      ' ',0,
      'T',0,
      'E',0,
      'S',0,
      'T',0,
      'E',0,
      'R',0,
   //string 2 - product
      20,  //length of string index
      0x03,  //descriptor type (STRING)
      'U',0,
      'S',0,
      'B',0,
      ' ',0,
      'T',0,
      'E',0,
      'S',0,
      'T',0,
      ' ',0
};

#define USB_CONFIG_HID_TX_SIZE 64
#define USB_CONFIG_HID_RX_SIZE 64
#include <pic18_usb.h>
#include <usb_desc_hid.h>
#include <usb.c>



source file:
Code:

#include <main.h>

/* TODO: Use usb_put_packet() to transmit data to USB HID,
using USB_HID_ENDPONT for the endpoint and the payload size
needs to match USB_CONFIG_HID_TX_SIZE. Use usb_get_packet()
to read incomming data, using USB_HID_ENDPOINT for the
endpoint. usb_enumerated() can be used to see if connected to
a host and ready to communicate. */

void main()
{
   usb_init_cs();

   while(TRUE)
   {
      // USB code
      usb_task();



      //TODO: User Code
   }

}


Hex file:
https://yadi.sk/d/WYqKKj5633zMWV

*20mhz/pll5

Thanks!


Last edited by biomed12 on Tue Dec 20, 2016 6:57 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 2:08 am     Reply with quote

Always tell us your compiler version...

I would be explicitly enabling the USB VREG (VREGEN), and disabling LVP. If you look at the CCS examples, the fuses they use for the 4550, are:

HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN

The Wizard, is a very good way of getting things 'wrong'... Better to work out your own set of fuses for the chip, make sure they are running, and then use these for all your projects on that chip.

However one thing leaps out in your string descriptor. No serial number. The CCS HID device descriptor (which you are presumably using, since you don't post your own one), includes the flag to require this.
Serial numbers in USB are only 'mandatory' on MSC devices. However they are recommended on HID devices (except keyboard and mouse). Microsoft use the serial number in their HID driver to generate the instance ID. With the flag set, and the number missing, I don't think the device will enumerate.
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 7:06 am     Reply with quote

Ttelmah wrote:


However one thing leaps out in your string descriptor. No serial number. The CCS HID device descriptor (which you are presumably using, since you don't post your own one), includes the flag to require this.


How can I repair this issue?
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 8:08 am     Reply with quote

Put a serial number in your string descriptor. Look at the examples.
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

PostPosted: Mon Dec 19, 2016 5:31 pm     Reply with quote

Ttelmah wrote:
Put a serial number in your string descriptor. Look at the examples.


Compiler Version: 5.064

I think the problem is windows 10. Because I tried a comlete project hex file which has been shared on github, It doesn't work, too.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Tue Dec 20, 2016 1:58 pm     Reply with quote

Why not just try adding the serial number?.

The point is that W10, is much 'stricter' about errors than the older OS's. It'll not allow things to work, that you could 'get away with' on the older systems. Forces you to get things 'right'. Don't assume anything you download will work correctly with your hardware (90% of posted code, when you look at it only works by 'luck').
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

PostPosted: Tue Dec 20, 2016 6:01 pm     Reply with quote

The device has a serial number as you see in the link below.

http://i.hizliresim.com/vXbdRA.png

EDIT: The problem is solved and i added the explanation to the first message's first line.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group