Author Topic: General question about USB  (Read 16591 times)

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
General question about USB
« on: December 17, 2013, 11:10:56 am »
Hello,

I have two boards:
An explorer board
and
A prototype board I'm working on

The explorer board detects if a USB is already plugged into the computer and does handshaking to attach.
The prototype board only is detected if it is physically put into the port then it does handshaking to attach.

I use the same software on both boards.

I'm not even sure if the problem is hardware or software.

I'm not even sure how to approach this problem, so any general help is welcome.


,Jim

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: General question about USB
« Reply #1 on: December 17, 2013, 11:19:31 am »
Are these embedded host boards that are detecting attached devices? And the explorer board can detect a device that is already attached on power up, while the other board only detects devices that are attached after power up?

Or are the boards USB devices that attach to a host PC? And the host PC detects the explorer board if it is already attached when the PC powers up, while the host PC detects the other board only if it is attached after the PC has booted?

Or? 

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
Re: General question about USB
« Reply #2 on: December 18, 2013, 12:18:03 pm »
>Or are the boards USB devices that attach to a host PC? And the host PC detects the explorer board if it is already attached when the PC powers up, while the host PC detects the other board only if it is attached after the PC has booted?

Almost this one.  They are standalone boards connected by a USB cable to a PC.
When the PC is on, and the board is programmed and off, I turn on the board.  The explorer board will handshake a connection.  The prototype board does not.

Chip is the same on both boards: PIC24FJ256GB110

The explorer board(works) is connected with an A->micro USB connection
The prototype board(issues already plugged in) is connected with an A->B connection

I'm confused to how to even approach this problem, so anything you got in terms of general advice is welcome. 

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
Re: General question about USB
« Reply #3 on: December 18, 2013, 01:19:02 pm »
This question just confuses my hardware noob self.  Maybe this isn't even the right forum to ask, but I'm trying to get at least one suggestion to help me along.

Here is a link to my post on microchip forums:http://www.microchip.com/forums/tm.aspx?tree=true&m=765098
« Last Edit: December 18, 2013, 01:57:22 pm by goodnewsjim »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: General question about USB
« Reply #4 on: December 19, 2013, 11:20:57 am »
One thing that would cause this is if the PC detects your board when it's not powered, tries and fails to enumerate it, and gives up. The PC then has no way of knowing when the board powers up and is ready to communicate.

On attachment, the board should either enumerate or prevent the pullup on D+ from indicating attachment until the board is ready.

Check DPPULUP (U1OTGCON<7>)?

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
Re: General question about USB
« Reply #5 on: December 19, 2013, 01:54:00 pm »
I'd like to thank you Jan for helping.  This is a really technical/arcane question, so anything you can give me helps.  This is the final problem to solve before the product is completely done. It works now, but it needs to be able to detect devices on USB when already plugged in and powering on of course.  We can't ask everyone to unplug/plug stuff in.


I get the first part of the handshake.  The whole handshake doesn't complete though.
It seems like on both boards U1OTGCON.DPPULUP=0 throughout the handshake.

I get into this part on both boards as the first part of the handshake:
if(USBDeviceState == ATTACHED_STATE)
    {
        /*
         * After enabling the USB module, it takes some time for the
         * voltage on the D+ or D- line to rise high enough to get out
         * of the SE0 condition. The USB Reset interrupt should not be
         * unmasked until the SE0 condition is cleared. This helps
         * prevent the firmware from misinterpreting this unique event
         * as a USB bus reset from the USB host.
         */

        if(!USBSE0Event)
        {
            numtimessofie=1;
            USBClearInterruptRegister(U1IR);// Clear all USB interrupts
      
            USBResetIE = 1;             // Unmask RESET interrupt
            USBIdleIE = 1;             // Unmask IDLE interrupt
            USBDeviceState = POWERED_STATE;
        }
    }

But then I don't ever get another event to call: USBDeviceTasks() in USB Generic Driver Demo from Microchip application library for my prototype board, but the explorer gets some more events.

You know what is really strange?  Yesterday I did get another event to call it, but U1IR.URSTF was equal to 0(Prototype) instead of 1(explorer-works)

« Last Edit: December 19, 2013, 02:26:30 pm by goodnewsjim »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: General question about USB
« Reply #6 on: December 19, 2013, 05:35:00 pm »
When you get here:

if(USBDeviceState == ATTACHED_STATE)

do you enter POWERED_STATE?

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
Re: General question about USB
« Reply #7 on: December 19, 2013, 07:46:49 pm »
Yes I get to POWERED_STATE, but the interrupt doesn't get called again after that one.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: General question about USB
« Reply #8 on: December 20, 2013, 11:32:57 am »
Do you get to USBDeviceInit?

In other words, how far do you get in USBDeviceTasks?

goodnewsjim

  • Frequent Contributor
  • ****
  • Posts: 52
Re: General question about USB
« Reply #9 on: December 20, 2013, 05:48:58 pm »
Jan, 

Tseuno solved it on the Microchip boards.
We now have a product that will be ready to ship once we get the Vendor and Pid from Microchip :)

A hearty thank you to your help here.  I wouldn't have been able to do the C# code without you.  I never coded in C# until this month.  There'd be no way I could get the arcane technical details without your help, not to mention the code that runs the whole thing!

Man I'm at a nice high right now.  I got what these guys needed for me to do at this place.  I wasn't even sure I could do microchip programming, but I knew since I knew coding I could give it a shot. Now it is done :)

Thank you so much Jan.  I have your book and I'm poking through it.  But you must know yourself that your support and the code you supply is worth more than dozens of books.

,Jim

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: General question about USB
« Reply #10 on: December 20, 2013, 05:56:56 pm »
Tsuneo is often very helpful here as well. Here is the solution (the board with the problem had an external pull-up).

http://www.microchip.com/forums/tm.aspx?high=&m=765098&mpage=1#767088