How to use PIC18 with MCP USB Chip to do HID?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2016
    Posts
    33

    Default How to use PIC18 with MCP USB Chip to do HID?

    Hello all,

    I would like to create a mouse device using a pic18f24j50 and a mcp2200 or mcp2221 USB chip to do HID.

    Both these chips come with proprietary DLLs.So I am not sure how I can use them in PicBasic.

    I am trying to send HID descriptor to a pc using I2C to USB chip or UART to USB chip.

    Any idea how this can be done?

    There are open source C libraries for them as well but not sure if it's possible to use C in basic.

    I would like to use my existing and working Basic code.The only way I am thinking is to change the firmware of the chips with a pic firmware and load usb_hid.c to create an interface to do it.

    I appreciate any help.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    You seem a little confused. In particular
    I am trying to send HID descriptor to a pc using I2C to USB chip or UART to USB chip
    The pic18f24j50 already has USB full speed hardware built in and PIC Basic has all the necesary "libraries" to implement HID.

    Perhaps you should say what you trying to acheive in broad terms.

    USB is very confusing to start (and sadly for most of us still continues to be). Try building one of the samples and try changing it a little. Also sadly you need to hit the books - the obvious one being USB complete by Jan Axelson or alternatly USB in a Nutshell.
    George

  3. #3
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    I got the onboard USB working with EASYHID and the hid libraries but I would like to replace it with USB chip to get over vendor id problem.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    You can set the VID and PID (vendor id and product id) to anything you like. Look in the descriptor file.

    BTW the MCP 2200 id just a pre-programmed 18F14K50. See this article http://hackaday.com/2011/01/18/mcp22...-your-bidding/
    Last edited by towlerg; - 10th June 2016 at 15:13. Reason: old and stupid
    George

  5. #5
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    I am trying to change more than VID and PID in the MCP2200 descriptor but there is no way to do it using the methods described.There is no HID mouse report descriptor in the descriptor. Basically I want to add hid mouse report descriptor to the MCP2200 descriptor and send data packets using PIC18 through UART OR I2C. In other word: A mouse using PIC and a USB Bridge.I don't want to use the onboard USB as it doesn't have a vendor id and I want to release the final code as an open source project. Am I missing anything?

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    Am I missing anything?
    Simple answer, yes.

    The MCP2200 is a preprogrammed PIC, which appears to the world as a USB to Serial convertor. Ading a mouse descriptor and the necesary software to service the descriptor is essentially impossible (no flames please). You would be much better of starting with a 18F14K50, modifying a HID sample.

    The data sheet gives details of how to change it's PID (among other things). From the data sheet -

    The configuration utility provided by Microchip allows the user to configure the MCP2200 to custom defaults. The configuration utility (shown in Figure 2-1) connects
    to the device’s HID interface, where all of the configurable features can be set.
    Name:  Untitled.jpg
Views: 2173
Size:  93.9 KB

    .I don't want to use the onboard USB as it doesn't have a vendor id
    Incorrect. The VID and PID are changed in the descriptor file which will be part of the compiled project.

    eg The portion of gen_desc.bas which defines the VID (among other things), in this case 04D8 hex.
    Code:
    DeviceDescriptor
    	retlw	(EndDeviceDescriptor-DeviceDescriptor)/2	; Size of this descriptor in bytes
    	retlw	USB_DESCRIPTOR_DEVICE	; DEVICE descriptor type
    	retlw	0x10		; USB Spec Release Number in BCD format - 1.10 (low byte)
    	retlw	0x01		; (high byte)
    	retlw	0x00		; Class Code
    	retlw	0x00		; Subclass code
    	retlw	0x00		; Protocol code
    	retlw	USB_EP0_BUFF_SIZE	; Max packet size for EP0
    	retlw	0xD8		; Vendor ID - 0x04D8 is Microchip Vendor ID (low byte)
    	retlw	0x04		; (high byte)
    	retlw	0x0C		; Product ID: PICDEM FS USB (DEMO Mode) (low byte)
    	retlw	0x00		; (high byte)
    	retlw	0x00		; Device release number in BCD format (low byte)
    	retlw	0x00		; (high byte)
    	retlw	0x01		; Manufacturer string index
    	retlw	0x02		; Product string index
    	retlw	0x00		; Device serial number string index
    	retlw	NUM_CONFIGURATIONS	; Number of possible configurations
    EndDeviceDescriptor
    I don't understand your references to mice?
    Last edited by towlerg; - 15th June 2016 at 14:56.
    George

  7. #7
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    That's not what I wanted to hear but at least I won't spend more time on it. My goal is to avoid the legal issues as this is an open source project and I can't legally tell people use our vendor id according to USB dot org.So in order to create a USB open source product I want to use a hardware chip to replace the software part so users can use the vendor id in the USB chip as in that case I am not releasing the VID or PID.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,515


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    I must admit the pic usb I/f is not an area I have studied or even used but I would have thought that if you want your "device" to appear to the usb host as a mouse then the descripter to use would be that of a generic mouse device.doing otherwise would entail the need to provide host driver code as well.
    have a look at the Arduino mouse library and maybe copy its functionality and hid descripter .

    then again I might be completely wrong
    Warning I'm not a teacher

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: How to use PIC18 with MCP USB Chip to do HID?

    @Richard There are perfectly good examples of various HID devices in both samples and possibly the Wiki.

    I'm sure (well fairly) that as you are using a MicroChip device , you can use their VID. Just make sure that you don't use a PID that they are using.

    @picmilan If you are trying to do USB to serial wouldn't you be better off looking at CDC. I'm pretty sure that standard mouse drivers will not allow you to write to the mouse.


    Perhaps the following may help - HID is used because it does not require drivers to be written and installed on the PC. HID comes in may variants with the most commonly used for general projects to be vendor. In vendor mode (also called generic) the significance of the data read and written must be know by both PIC and PC. This is both flexible and powerful. Reports are fairly meningless in this mode.
    CDC is the USB Serial protocol and does require a driver on the PC. Microchip provide one for use with their devices which you can edit to suit the PID you select.

    I suggest you try the USB samples provided, making minor changes and hopefully get a feel for the joys of USB.
    Last edited by towlerg; - 16th June 2016 at 05:02.
    George

Similar Threads

  1. Olimex PIC-MCP-USB
    By Tawcafts in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st March 2012, 18:54
  2. PIC18 connect to USB thumb drive
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th April 2011, 19:15
  3. Usb hid
    By yatyas72 in forum USB
    Replies: 5
    Last Post: - 3rd December 2010, 16:45
  4. PIC18 USB Programmer
    By r0nd0m in forum Off Topic
    Replies: 1
    Last Post: - 23rd February 2009, 16:59
  5. PIC18 USB simple example needed
    By harryweb in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th September 2005, 23:20

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts