disconnect USB - is it possible?


Closed Thread
Results 1 to 9 of 9
  1. #1

    Question disconnect USB - is it possible?

    Hi there!

    PicBasicPro has four usb commands, read, write, init and service. Clean and simple indeed. However, one command is missing, DISCONNECT!
    Is it possible to disconnect your current usb session without touching the cable?

    When you plug an USB device you hear ding-dong and when you unplug it you hear dong-ding. This quit convenient for the users...

    Let's say that you have a cable connected between your PIC and your PC, then you turn on your PIC, in the code first there will be USBINIT and after that you should call quit frequently USBSERVICE and very shortly after this you will hear the ding-dong sound. I do not know how many times you have to call USBINIT before you hear that ding-dong sound. Do you know that?

    I would need to disconnect (hear the dong-ding sound) from my application, without unplugging the cable. How is that possible?

    I tried skipping the call of USBSERVICE, but that did not do the trick.
    I believe that you really have to hear the dong-ding sound before you really can believe that your application has been unplugged/disconnected.

    If you can, please help...

  2. #2
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94

    Default

    Hi,

    Quote Originally Posted by keymuu View Post
    I do not know how many times you have to call USBINIT before you hear that ding-dong sound. Do you know that?
    this can vary. I will reply tomorrow with a good example of how to do this unless somebody else replies first but for now look up posts from Darrell Taylor regarding the USB stuff as a hint.

    I would need to disconnect (hear the dong-ding sound) from my application, without unplugging the cable. How is that possible?
    Try:

    Code:
        UCON.3 = 0                  ' UCON register bit 3 (USBEN) enables/disables
                                    ' the USB - see page 164 18F4550 datasheeet
    Hope this helps in the mean time

    Cheers

    Rob

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Totally untested thought...
    what happen if you stop calling USBSERVICE?

    thereafter, what may happen if you use the method shown in the famous known "POST 148"

    Code:
    ' snip
    usb_device_state   var byte EXT
    CONFIGURED_STATE   CON EXT
    
    DoUSBinit:
        pause 500
        usbinit ' initialise USB...
        repeat  ' kick-start it
            usbservice
        until usb_device_state = CONFIGURED_STATE
    POST 148
    http://www.picbasic.co.uk/forum/show...&postcount=148

    EDIT 1:
    Here's the complete list for usb_device_state var
    Code:
    ; USB Device States - To be used with [byte usb_device_state]
    #define	DETACHED_STATE		0
    #define	ATTACHED_STATE		1
    #define	POWERED_STATE		2
    #define	DEFAULT_STATE		3
    #define	ADR_PENDING_STATE	4
    #define	ADDRESS_STATE		5
    #define	CONFIGURED_STATE	6

    EDIT:2
    I don't think you can relly on that ding-dong noise... check USBDemo, it has this fake led showing if the device is connected or not. An another alternative is to use USBDeview...
    http://www.nirsoft.net/utils/usb_devices_view.html
    Last edited by mister_e; - 10th November 2008 at 19:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4

    Default

    Quote Originally Posted by Rob View Post
    Hi,
    this can vary. I will reply tomorrow with a good example of how to do this unless somebody else replies first but for now look up posts from Darrell Taylor regarding the USB stuff as a hint.

    Try:

    Code:
        UCON.3 = 0                  ' UCON register bit 3 (USBEN) enables/disables
                                    ' the USB - see page 164 18F4550 datasheeet
    Thank you Rob !!!

    UCON.3 ' USB Control Register, USB Module Enable Bit,0=Detached, datasheet 17.2.1
    That did do the trick, nice and smooth, without any problems, without any other lines of code... very nice indeed

    Quote Originally Posted by mister_e
    Totally untested thought...
    what happen if you stop calling USBSERVICE?
    Nothing, no dong-ding, nothing you could measure. Or maybe you can, bat because I did not hear the dong-ding I skipped rest of the "testing"...

    Quote Originally Posted by mister_e
    thereafter, what may happen if you use the method shown in the famous known "POST 148"
    I will take a closer look at it in the future. At the moment I'm quite happy with that one line solution...

    Thank you again Rob and Mister_e thank you indeed

  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94

    Default

    Hey Keymuu,

    glad that worked for you. The stuff to read that I was going to point you to today is the post that Steve is referring to above - this will help you achieve USB enumeration correctly.

    Good luck

    Rob

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Yup, all good stuff to know. One day i may need to do it as well.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257

    Default

    Quote Originally Posted by keymuu View Post
    Thank you Rob !!!

    UCON.3 ' USB Control Register, USB Module Enable Bit,0=Detached, datasheet 17.2.1
    That did do the trick, nice and smooth, without any problems, without any other lines of code... very nice indeed


    Nothing, no dong-ding, nothing you could measure. Or maybe you can, bat because I did not hear the dong-ding I skipped rest of the "testing"...


    I will take a closer look at it in the future. At the moment I'm quite happy with that one line solution...

    Thank you again Rob and Mister_e thank you indeed
    Guys,

    Having trouble compiling UCON.3= 0

    Getting a syntax error with PB2.47. Anyone else?

    Squib

  8. #8
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35

    Default

    Quote Originally Posted by Squibcakes View Post
    Guys,

    Having trouble compiling UCON.3= 0

    Getting a syntax error with PB2.47. Anyone else?

    Squib
    I had the same problem - have now bought PBP2.6 upgrade but have not tested yet but I got around this in assembler where UCON is recognised:
    Code:
                T0CON.7 = 0     ' Disable USBservice interrupts
    '           UCON.1 = 1      ' UCON not defined in PBP 2.46
    @	        clrf	UCON	; Disable USB & detach from bus
    @	        clrf	UIE  	; Mask all USB interrupts
    Peter

    PS I have Timer0 running on 1 mSec interrupts - the Interrrupt handler simply doing an USBservice and returning - turned this off here also
    Last edited by FinchPJ; - 24th August 2010 at 10:02. Reason: Postscript

  9. #9
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35

    Default

    I have just had a chance to check this out and it works fine - add:
    Code:
    UCON    var byte EXT
    to your PBP 2.46 program and it should solve the problem! You can now refer to for example:
    Code:
           UCON.3 = 0
    Peter

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  3. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  4. Replies: 15
    Last Post: - 30th October 2007, 19:25
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

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