Software on PIC will come in loop after disconnect USB connection


Closed Thread
Results 1 to 16 of 16

Hybrid View

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

    Default

    Hi Squib,

    I can't take credit for the idea. It's an option on the Microchip USB development board, and
    in the USB C firmware.

    There's no reason to enable the USB module if it's not attached, so it's not a bad idea to
    add in.
    Regards,

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

  2. #2
    Join Date
    Sep 2007
    Posts
    9

    Default

    Hi Bruce, thank you for your almost exelent and simple sollution. Almost exelent because it will cost me 1 I/O and I don't have one I/O left. I have made a mistake because after testing this code again it was working.

    USBwriteStatus:
    USBService
    USBOUT 3, USBBUFFER ,CNT_UIT, exitusbwritestatus
    exitusbwritestatus:
    RETURN

    However this sollution has a disadvantage because when the outgoing USBBuffer is full it will also goto "exitusbwritestatus" without sending the information via USB, so some status information from PIC to PC will be lost.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    You should be able to determine if it's plugged-in or not by monitoring the usb_device_state variable.
    Code:
    usb_device_state   VAR BYTE EXT
    CONFIGURED_STATE   CON EXT
    
    IF (usb_device_state = CONFIGURED_STATE) THEN
        ; OK to send
    ELSE
        ; Detached or Enumerating, don't try to send.
    ENDIF
    DT

  4. #4
    Join Date
    Sep 2007
    Posts
    9

    Default

    Hi Darrel, I've tried it however it is not working. I've used the following.

    IF (usb_device_state = CONFIGURED_STATE) THEN
    high dataled
    ELSE
    low dataled
    ENDIF

    During USB connection the dataled is on. However the status of the dataled will not change when the USB cable will be disconnected. When I connect the cable in, for short time the dataled will be turned off and within about 300msec it will be turned on. I think that the Led will be turned off during enumeration.

    Do I something wrong why it is not working?

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Hi Ronald,

    I've done something similar before, but I didn't have a USB breadboard handy at the time I replied.

    I've dug out the old mister_e usbdemo breadboard.
    Blown off the dust with a half a can of "Dust-Off" ...

    ... and am taking a look.

    Hoping I can figure it out.

    DT

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

    Default

    Ditto, Doesn't work for me either...

    Cheers
    Squib

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by Squibcakes View Post
    Ditto, Doesn't work for me either...

    Cheers
    Squib
    That's right. Kick him while he's Down.

    Working on it.

    DT

Similar Threads

  1. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 21:17
  2. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 06:02
  3. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 13:00
  4. Two USB devices with same software, easyHID
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st October 2007, 07:19
  5. PIC 2 PIC wireless connection
    By MegaADY in forum General
    Replies: 1
    Last Post: - 24th June 2004, 02:46

Members who have read this thread : 0

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