Multiple USB devices in a single 18f

Page: 12 > Showing page 1 of 2
Author
MikeN
Senior Member
  • Total Posts : 176
  • Reward points : 0
  • Joined: 2005/11/03 06:26:06
  • Status: offline
2007/06/14 07:16:07 (permalink)
0

Multiple USB devices in a single 18f

Hello all
 
I would like to be able to use one of the 18f family with usb to provide two CDC ports - one to be an RS232 output, the other to generate a parallel i/o extender. I would like both to be CDC, so no need for PC driver writing, and I can design a protocol to set/clear/read pins as required.
 
I want the data streams to be separate so that exisitng comms programms can be run without needing extra work to indicate tha the packet is for the parallel i/o or the RS232 output.
 
It seems to me that I may need a software usb hub to run the two streams, as I cannot see any alternative, but where do I find out about that?
 
I hope an expert can help point me in the right direction!
 
Best Regards

Mike Newsome, MJN Design Solutions, England
#1

28 Replies Related Threads

    DarioG
    GM ist tot...
    • Total Posts : 52256
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/06/14 07:22:06 (permalink)
    0
    Well,
    in theory a single 18F part can enumerate 2 interfaces or anyway "2 different devices", in your case 2 COM ports. Someway, i.e. by COM number or with some other method, you should be able to talk to both, separately.
    Or, you can build 2 boards, with different Product IDs, and this works for sure (almost  Smile)

    You could also use a HID or a custom (MPUSBAPI) device to do this: in this case, there would be no need to create 2 interfaces, since you would send, for example, 2 different "sets" of bytes, one, say, marked as "type 1" and the other marked as "type 2", and you would handle these (max 64-bytes long) packets in your firmware. I do this to talk, for example, to either a 485 network or a 2.4GHz wireless network.

    IMO, the second approach is simpler at the firmware side, with some inconvenience at the PC side, i.e. you can't use 232 APIs but have to write some code... but this is not much complicated at all, and several examples are available for VB, VC, .net etc.

    Dario Greggio
    --
    Rule of thumb: Always read inputs from PORTx and write outputs to LATx. If you need to read what you set an output to, read LATx.
    #2
    Pacer
    Super Member
    • Total Posts : 1171
    • Reward points : 0
    • Joined: 2004/12/01 09:29:20
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/06/14 09:14:09 (permalink)
    0
    Personally, if this is a commercial job, I would avoid using CDC as the driver usbser.sys appears to be quite flaky and varies from OS to OS. Knowing which com port to use seems to cause endless problems to people. Also having two channels may be beyond capability of the Microsoft drivers to understand. (Or maybe not but you'd need to experiment). HID would certainly give you better control if the throughput is adequate.
     
    By the way, if it came to compund device with a hub, I think a hub chip would be easier than firmware simulation of one, and not terribly expensive. It all depends on the parameters of the project.
    #3
    andychalgrove2
    Starting Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2006/03/29 15:09:22
    • Location: 0
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/06/24 06:51:41 (permalink)
    0
    I have a similar issue!  The Windows usbser.sys driver only recognises one USB device as one serial port.  So you are right that you need to either a) write a custom driver (and what a headache that is to the uninitiated) or b) add hub functionality so the serial ports look like different cdc devices

    Ive asked Microchip support a number of times and currently the replies are all over the shop!  I have a "you cant do that because you have no downstream ports" (I had pointed out that I didnt need them as I wanted to make a compound device in my query before getting that response).  I then had a "yes you can do it...and we are working on a simular project internally" but the timescale was long.  The I had another "no you cant do it because you need hub functionality and the 18F4550 is a slave only device". Then I had a nice chap tell me that the internal microchip project was a compound device...great...but he then went on to descibe adding interface descriptors that I thought was the way you produce a composite device (not supported by usbser.sys).

    I also have a suspicion that the hub repeater block in a hub chip actually takes data from the bus regardless of where its addressed and passes it on.  This is important, because a quick look at the datasheet for the 18f4550 shows an address register, that in the enumeration gets loaded with the USB address of the device.  Now if USB then proceeds to try to enumerate a second device (and does not use you're new device address) I have a feeling that the PIC will ignore the traffic as its not addressed to the PIC.

    Having a look at chapter 11 of the usb spec isnt a lot of help.

    But there you go...
    Andy
    #4
    Brem
    Junior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2005/09/22 12:30:34
    • Location: Amsterdam
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/06/24 11:03:45 (permalink)
    0
    For my hobby projects I use a firmware that emulates a FTDI2232, it gives you two virtual com ports. I'll try to attach a demo project for a 4550.
     
    #5
    Pacer
    Super Member
    • Total Posts : 1171
    • Reward points : 0
    • Joined: 2004/12/01 09:29:20
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/06/24 14:12:04 (permalink)
    0
     also have a suspicion that the hub repeater block in a hub chip actually takes data from the bus regardless of where its addressed and passes it on.  This is important, because ...

    Very good point! Hub chip then.
    #6
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    FTDI2232 emulation with 18F2550/4550 2007/07/17 19:45:40 (permalink)
    0
    ORIGINAL: Brem

    For my hobby projects I use a firmware that emulates a FTDI2232, it gives you two virtual com ports. I'll try to attach a demo project for a 4550.


     
    Nice. I did not notice that we have a hidden treasure here.
     
    Just to confirm it is working, I have ported to PICkit 2.
    http://forum.microchip.com/tm.aspx?m=267849
     
    Right now the FTDI site is down so I can not download the driver. However I find that the FTDI driver is already inside Windows XP SP2. So I do not need even a driver. I need to test this more. Thanks for sharing.
    #7
    michbound
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2005/12/01 09:34:09
    • Status: offline
    RE: FTDI2232 emulation with 18F2550/4550 2007/07/19 08:45:13 (permalink)
    0
    xiaofan,
     
    This looks good, now if someone can make the CDC interrupt driven rather than polling and get it to work well that would be nirvana!
     
    Thanks
    #8
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: FTDI2232 emulation with 18F2550/4550 2007/07/19 09:43:18 (permalink)
    0
    Try this thread.
    http://forum.microchip.com/tm.aspx?m=173421
    Unfortunately all the attachments are now gone. Quite annoying!
     
    I am in the process of reading the USB frame code and searching the forum for more details. There are many good information in the forum.
     
    Tip: use Google to search the forum
     
    Eg: "interrupt driven firmware site:http://forum.microchip.com" and it will show quite some relevant result.
    Eg: http://forum.microchip.com/tm.aspx?m=136955
    #9
    AutumnForester
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2007/08/12 06:19:14
    • Location: 0
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/08/16 02:11:55 (permalink)
    0
    ORIGINAL: Brem

    For my hobby projects I use a firmware that emulates a FTDI2232, it gives you two virtual com ports. I'll try to attach a demo project for a 4550.


     
    Has anybody a copy of this as the file no longers seems to be here.
     
    thanks
    #10
    Brem
    Junior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2005/09/22 12:30:34
    • Location: Amsterdam
    • Status: offline
    RE: Multiple USB devices in a single 18f 2007/08/16 02:59:39 (permalink)
    #11
    izua
    Super Member
    • Total Posts : 339
    • Reward points : 0
    • Joined: 2007/01/20 18:07:49
    • Location: 0
    • Status: offline
    RE: Multiple USB devices in a single 18f 2008/01/29 04:37:18 (permalink)
    0
    What baud rate do the ports use?
    I've only found 0x03 in the code, and on 12MHz, 57600 is 2 and 38400 is 4 with BRGH set.
    Also, i have looked throughtfully into the code, but I can't seem to get a hang of it really well. On what pins are the serial ports? :D

    I've got this PIC to enumerate as a composite device, and i have installed the two ports.
    #12
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Multiple USB devices in a single 18f 2008/01/29 07:58:35 (permalink)
    0
    I think you are right that this is not a full USB-to-Serial converter implementation. It only implements the USB CDC-ACM part just like the Microchip CDC demo.
     
    Anyway, if you need real dual serial ports, FTDI2232 is a better option.
     
    Take note that the above emulation implementation can not be used in commercial projects due to the license limitation of FTDI drivers.

      USB_Links and libusb
    #13
    RoDeNtJe
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2007/06/16 02:04:54
    • Location: Belgium
    • Status: offline
    RE: Multiple USB devices in a single 18f 2008/05/17 06:25:07 (permalink)
    0
    Hi Brem,

    Have you by any chance updated your example to the v1.3 framework? If so, could you post it?
    Does it work faster than Microchip's CDC example?

    Best regards,
    RoDeNtJe
    post edited by RoDeNtJe - 2008/05/17 06:29:40

    It's nice to be important, but it's more important to be nice !
    #14
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Multiple USB devices in a single 18f 2008/05/17 06:33:43 (permalink)
    0
    It seems to me Brem's example is not so difficult to be converted to use V1.3 stack. After all, changes between V1.0 and V1.3 are not that much.
     
    Changes between V1.3 and V2.1 are more significant, at least due to the functional name changes and definition changes.

      USB_Links and libusb
    #15
    buddacedcc
    Senior Member
    • Total Posts : 155
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: Multiple USB devices in a single 18f 2009/02/04 01:55:07 (permalink)
    0
    ORIGINAL: Brem

    Sure..



    Hi brem, your firmware implement hardware flow control ?
    #16
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: Multiple USB devices in a single 18f 2009/02/04 17:58:54 (permalink)
    0
    I think the answer is no since the UART part is not implemented at all.

      USB_Links and libusb
    #17
    buddacedcc
    Senior Member
    • Total Posts : 155
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: Multiple USB devices in a single 18f 2009/02/09 02:08:39 (permalink)
    0
    I do some test and RTS works. But CTS don't work correct in my test. This signal are managed automatically in putcUSBVCPA() and getcUSBVCPA()? 
    I think CTS should be set bye main application in pic.
    #18
    buddacedcc
    Senior Member
    • Total Posts : 155
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: Multiple USB devices in a single 18f 2009/03/31 03:01:53 (permalink)
    0
    Hi, news about my testing with VCP. CTS is manage by application and value is correct displayed in PC rs232 terminal but terminal (with hardware flow control enable) ignore cts status and send anytime data.
    RTS is not managed by usb/vpc code into PIC. This value is always true ... tried manual change by r232 terminal but PIC value is always 1. Any idea ho can I implement RTS?
    post edited by buddacedcc - 2009/03/31 03:21:21
    #19
    chinzei
    Super Member
    • Total Posts : 2249
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: Multiple USB devices in a single 18f 2009/03/31 07:29:35 (permalink)
    0
    But CTS don't work correct in my test.

    CTS is not supported on CDC spec.
    If you are coding the host app, too, use RLSD (DCD) instead.


    CDC SerialState bitmap and Windows serial API / SerialPort class

    CDC SerialState | Windows serial API | .Net FrameWork
    Notification | GetCommModemStatus ClearCommError SetCommMask | SerialPort class
    | WaitCommEvent | Properties Events
    _________________|____________________________________________________________|__________________________________________
    D0 bRxCarrier | MS_RLSD_ON COMSTAT.fRlsdHold EV_RLSD | CDHolding SerialPinChange.CDChanged
    D1 bTxCarrier | MS_DSR_ON COMSTAT.fDsrHold EV_DSR | DsrHolding SerialPinChange.DsrChanged
    D2 bBreak | --- lpErrors CE_BREAK EV_BREAK | --- SerialPinChange.Break
    D3 bRingSignal | MS_RING_ON --- EV_RING | --- SerialPinChange.Ring
    D4 bFraming | --- lpErrors CE_FRAME EV_ERR | --- SerialError.Frame
    D5 bParity | --- lpErrors CE_RXPARITY EV_ERR | --- SerialError.RXParity
    D6 bOverRun | --- lpErrors CE_OVERRUN EV_ERR | --- SerialError.Overrun

    RLSD = DCD (CD)


    6.5.4 SerialState (PSTN120.pdf p32)
    Table 31: UART State Bitmap Values
    http://www.usb.org/developers/devclass_docs/CDC1.2_WMC1.1.zip
    GetCommModemStatus
    http://msdn.microsoft.com/en-us/library/aa363258(VS.85).aspx
    ClearCommError
    http://msdn.microsoft.com/en-us/library/aa363180(VS.85).aspx
    COMSTAT
    http://msdn.microsoft.com/en-us/library/aa363200(VS.85).aspx
    SetCommMask
    http://msdn.microsoft.com/en-us/library/aa363435(VS.85).aspx
    SerialPort Class
    http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx


    Any idea ho can I implement RTS?

    Because of the bug of usbser.sys, RTS value is altered when you put DTR.

    http://www.microchip.com/forums/tm.aspx?m=400476&#401017

    Tsuneo

    [EDIT] swap Break and Ring on SerialPort event
    post edited by chinzei - 2009/04/01 00:32:19
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2017 APG vNext Commercial Version 4.5