USB PIC without USB Connection


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default USB PIC without USB Connection

    I have stumbled across a problem with my USB PIC application. I am using a PIC 18F2550 which works fine and has been programmed using PICBasic Pro. Basically the device needs to be standalone, but when connected to the USB port, it can transfer data to and from the PIC. As i say, this is all working fine, or so i thought !!

    During development, the PIC has always been plugged into the USB port with the PC turned ON. Today i unplugged it and found that it no longer worked when it is unplugged from USB. I am guessing this is due to it looking for data on the USB, and when there is none it hangs.

    Plug it back in, and all is fine.

    Does anyone have reasonable experience with PICBasic Pro and these PICs. The base code was generated using EasyHID.

    Obvioulsy i can send the code i have so far, but i think the problem lies in this DoUSBOut routine. Is there a way for it to say, if no USB connection RETURN.

    Code:
    ' ************************************************************
    ' * wait for USB interface to attach                         *
    ' ************************************************************
    DoUSBOut:
       USBBufferCount = USBBufferSizeTX              ' TX buffer size
       USBService                                    ' keep connection alive
       USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
    Return
    To clarify, I want the PIC to function normally whether the PC is ON or OFF and if the USB is connected or not, and only the sending / receiving of data to take place when I load the VB application.

    Although this is not a data logger aplication, has anyone worked on a USB datalogger application. ie it collects data, but when it is plugged inot the USB it can then tranfer this data. I need it to be so that no user intervention is required to put it in USB mode.

    Many thanks.

    Steve

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    Dedicate a single I/O-pin as USB bus sense. Use a large value pull-down resistor of around 100K to pull this pin to ground when the USB cable is not connected.

    Connect the node between this pin and the pull-down to USB +V on your USB cable connector. Once the USB cable is plugged in, the USB sense pin will be pulled-up to +V.

    Until this pin senses the USB connection, have your program avoid calling any USB sub-routines or issuing any USB commands. This is how Microchip does it with the USB PIC demo board.

    You might want to download the docs for the Microchip USB demo board and take a peek at the schematics/code for reference.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Ahh, you come up trumps again Bruce, thank you. I was starting to think after all this work, a small problem like this would mess it all up for me!!

    I've had a look at the USB PIC Demo docs and i think the attached highlighted diagram is what you are talking about?

    So i am guesing in the code i need to put something along the lines of

    Code:
        If PORTA.1 = 1 Then ' or what ever port is the USB_ATTACH line
            Gosub DoUSBIN
            Gosub DoUSBoUT
        Else
        EndIf
    Thanks again,

    Steve
    Attached Images Attached Images  

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Ah, just thought of a problem. Its not that the USB device is connected or disconnected, as i have it powered by the USB port anyway. I believe that it is failing to work as it is expecting data during the DoUSBOut routine, but when the PC is off, there is no data.

    With this previous suggestion, this will be only to detect whether or not the device is plugged in or not. As with this device it will always be plugged into a USB port, whether the machine is powered on or not. If the PC is off, 5v will still be on the USB ports to keep this device powered up as usual.

    Hope this makes sense. Any other suggestion?

    Steve

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yep. That's the schematic. I'll let you work out the code.

    I haven't done much with USB without the connection, but if I did, I would use a flag bit to indicate the 1st connection, jump to a routine and issue USBINIT, then toggle the flag bit once the USB connection was broken. That way I could issue the USBINIT only once when the connection was initially made.

    You don't absolutely have to jump to a USBin or USBout routine unless you need to send/receive data over the USB port, BUT, you do need to use USBSERVICE frequently enough to keep the connection active.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Guess I should have asked, but I just assumed if you had the PC turned OFF, and the board still ran, that you were externally powering the board. None of my machines will provide power to a USB port when turned off.

    Sounds like you're plugged into a self-powered USB hub? If that's the case, then this approach obviously isn't going to do you any good.

    If you can't use another power source, then I suspect you'll need to dig into the datasheet and find a flag bit to help indicate USB activity.

    Can't offer you much help there since I've never done it yet.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Well, I've no idea if this would work with USB, as I've not worked with USB yet - but on some code I did for the LANC port control of Sony video cameras, I just have a short loop that tests for any activity at all on the LANC line - if no activity, I'd skip off to some other section of the code.

  8. #8
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default USB power leaching

    Quote Originally Posted by Tissy
    With this previous suggestion, this will be only to detect whether or not the device is plugged in or not. As with this device it will always be plugged into a USB port, whether the machine is powered on or not. If the PC is off, 5v will still be on the USB ports to keep this device powered up as usual.

    Hope this makes sense. Any other suggestion?

    Steve
    Not sure if this is for a commercial application, but stealing power from the USB bus without a properly enumerated device being attached is a blatant violation of the official USB spec...

    To do this properly, you'd want either (a) the device to be enumerated and active at all times or (b) receive power from a source external to the USB bus.

    John

  9. #9
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thanks for your more than constructive feedback John.

    Steve

  10. #10
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default Power

    You can still use Bruce's method of sensing whether the bus is active... The presence of a USB bus could allow your PIC to switch some FETs that activate a charging circuit, etc.

    Or, like Bruce mentioned, you can run in non-USB datalogging mode until a voltage is sensed on that pin. Then, enumerate and dump your data.

    Officially, your device is supposed to draw less than 100 mA of current during enumeration until it negotiates and is approved to receive higher power. If you're running on a laptop through a bus-powered hub, there's a chance that the computer might just say, "Sorry, no can do." There just isn't enough power available.

    And if the bus is idle (which means > 3 mS of inactivity), you're not supposed to draw more than I think 500 uA. Yes, microamps.

    Surf on over to usb.org, click on developers and then on discussion forums. You'll find a wealth of information and helpful engineers.

    They aren't too patient with people who haven't done some basic homework before asking questions, but the forums can be searched. Many of the most popular questions have been discussed ad absurdum already...

    John

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 12:00
  3. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  4. Replies: 15
    Last Post: - 30th October 2007, 19:25
  5. USB, PIC18F2550 and VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th November 2005, 18:37

Members who have read this thread : 1

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

Posting Permissions

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