Shop OBEX P1 Docs P2 Docs Learn Events
Detecting USB connection — Parallax Forums

Detecting USB connection

BasilBasil Posts: 380
edited 2008-08-26 04:27 in Propeller 1
Hi All,

In my application, I want to be able to talk to a PC over serial (via FTDI chip on the normal prop pins).
The problem I have is. When USB cable is NOTconnected, the prop resets whenever the program trys to send data to the serial port and gets itself into an endless cycle.

I want to be able to check is the USB cable is plugged in and boot in a different 'mode' if it is.

Is it possible to read the state of the RESn pin?

What im getting at is:
When USB cable is connected, this brings RESn low then high causing a reset on the rising edge, correct?

While the USB stays connected, RESn stays high during the reset. If I can read this pin then I can check if the prop has just been reset because of USB connection, or if it was a normal power on (in which case RESn would be low)

Does this sound dooable? I am at work so don't have all the datasheets with me...

Alec

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page

Post Edited (Basil) : 8/26/2008 1:06:34 AM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-26 03:23
    Alec,

    This is a well-known and oft-cited issue. See this thread for the reasons behind the problem and a solution. Short (but not very satisfactory) answer: put a 2.2K pullup on A30. If the board is your own design, modify it to include a 74LVC2G07 open-collector buffer pair between the USB chip and the Propeller, powered from the FT232R's VCCIO.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 8/26/2008 3:34:01 AM GMT
  • BasilBasil Posts: 380
    edited 2008-08-26 03:47
    Hi Phil,

    Thanks for the link.
    I had actually seen that in my searches. I don't actually mind the reset, in fact it makes some part of my code easier.

    The main reason for my asking is to find out if there was a way to detect if USB is connected upon powerup.

    If there is no way to check the status of the RESn pin on powerup (without the prop resetting) then the only way I can think of is in fact to add that resistor mentioned in the link you gave, then send a serial query down the line to a GUI on the PC
    If there is a response then obviously something is connected. If not, then there isnt.

    My problem now is I don't know how to implement a time out. eg, send 'hello'. If 'im here' is not recieved back within 5 seconds, then no connection, continue with program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-26 04:14
    Alec,

    Put the 2.2K pullup on A30 and a weak (~47K) pulldown on A31. When your program starts, poll A31. If it's high, you know the USB cable is connected. If it's low, check it several more times to ascertain that the PC is not sending data. If it stays low, chances are there's no USB dongle connected.

    If what you really want to know is whether the PC and the USB dongle/cable are connected, omit the pullup on A30. If A31 is low, don't raise A30, or you'll reset the Prop if just the dongle/cable is connected.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • BasilBasil Posts: 380
    edited 2008-08-26 04:18
    Will try that, thanks phil [noparse]:)[/noparse]

    I was hoping to avoid using an extra pin but If I can't avoid it...

    Thanks [noparse]:)[/noparse]

    Alec

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-26 04:25
    Alec, those aren't extra pins. A30 and A31 are the normal serial connections to the USB interface.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • BasilBasil Posts: 380
    edited 2008-08-26 04:27
    So they are [noparse]:)[/noparse] Im having a bad day!

    Thanks phil, Looks like im going to have some ugly 1/4w resistors sticking out of my nice SMT board :P

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
Sign In or Register to comment.