Hot!USB Interrupts and Attach Detection

Author
AGJ
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2012/10/01 22:01:02
  • Location: 0
  • Status: offline
2012/10/01 23:31:54 (permalink)
0

USB Interrupts and Attach Detection

Hi!
I'm using in my project the USB Host Stack library for communicate a PIC24F with a generic client device. I'm using the circuit attached in the image, based in the datasheet's recomendation (except for the A/D pin tied to resistor, because i don´t know what to do with this signal).
Just for start, I'm monitoring the different events in the "USB_ApplicationEventHandler" and turning on some LEDS, just for give me an idea about what is happening in the system. I was expecting that the indicator corresponding with the 'EVENT_GENERIC_ATTACH' will turning on when I connect my device, but nothing happens.
For this reason, I started to check the 'usb_host.c', where is "the heart" of the stack. With some similar tests, I realized that the main state machine in the USBTasks() function,  came and stay in the STATE_DETACHED and SUBSTATE_WAIT_FOR_DEVICE. In this moment, the only way that the system can jump to the next stage (STATE_ATTACHED) is with the 'U1IRbits.ATTACHIF' interrupt, but even connecting the device this interruption is never generated. Even, I tried to place in the circuit a fixed "emulator" of a full speed connected device, with a pullup 1.5K resistor from D+ to Vbus, but still nothing. 
According to my readings, this interruption is generated by hardware (doesn't depend of the stack) when the USB OTG module detects that the bus state is not SE0 and there has been no bus activity for 2.5 microseconds. The curious is that I'm also monitoryng the SE0 signal with the U1CONbits.SE0, and I can see how this signal turn OFF when i connect the device to the bus, and keep in this way until I disconnect, but the interruption still not being generated.
This is my code:
 

#include <stdio.h>
#include <stdlib.h>
#include "GenericTypeDefs.h"
#include "HardwareProfile.h"
#include "usb_config.h"
#include "USB/usb.h"
#include "USB/usb_host_generic.h"

_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx1 & FWDTEN_OFF )
_CONFIG2(IESO_OFF & PLLDIV_DIV2 & PLL96MHZ_ON & FNOSC_FRCPLL & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_NONE)
_CONFIG3( SOSCSEL_IO)

BYTE        deviceAddress;

BOOL InitializeSystem ( void ){ 
 _COSC=1;   
_NOSC=1; 
 _RCDIV=0; 
 _CPDIV=3; 
 _PLLEN=1;
    _PCFG = 0xffff;
    _TRISA0= 0;    _TRISA1= 0;    _TRISA2= 0;    _TRISA3= 0;    _TRISA4= 0;
    _TRISB0= 0;    _TRISB1= 0;    _TRISB2= 0;    _TRISB3= 0;    _TRISB4= 0;
    _TRISB5= 0;    _TRISB7= 0;    _TRISB8= 0;    _TRISB9= 0;    _TRISB13= 0;
    _TRISB14= 0;    _TRISB15= 0;   
return TRUE;} // InitializeSystem

BOOL USB_ApplicationEventHandler ( BYTE address, USB_EVENT event, void *data, DWORD size ){   
// Handle specific events
    switch ( (INT)event )    { 
      case EVENT_GENERIC_ATTACH:
            if (size == sizeof(GENERIC_DEVICE_ID))            { 
              deviceAddress   = ((GENERIC_DEVICE_ID *)data)->deviceAddress; 
              _LATA0=1;
              return TRUE;            }           
              break;
        case EVENT_GENERIC_DETACH: 
               _LATA1=1;          
              deviceAddress   = 0;           
return TRUE;
        case EVENT_GENERIC_TX_DONE:           // Not relevant in this moment.
        case EVENT_GENERIC_RX_DONE:           
        return TRUE;
        case EVENT_VBUS_REQUEST_POWER:
          _LATA2=1;           
           return TRUE;
        case EVENT_VBUS_RELEASE_POWER:                        // We aren't keeping track of power. 
            _LATA3=1;  
            return TRUE;
        case EVENT_HUB_ATTACH: 
            return TRUE;
            break;
        case EVENT_UNSUPPORTED_DEVICE:
          _LATB1=1;
          return TRUE;
            break;
        case EVENT_CANNOT_ENUMERATE:
             _LATB2=1;
            return TRUE;   
        break;
        case EVENT_CLIENT_INIT_ERROR:           
             return TRUE; 
             break;
        case EVENT_OUT_OF_MEMORY:           
              return TRUE;       
              break;
        case EVENT_UNSPECIFIED_ERROR:            // This should never be generated. 
             _LATB3=1;
             return TRUE;           
             break;
        case EVENT_SUSPEND:   
       case EVENT_DETACH:   
        case EVENT_RESUME:   
       case EVENT_BUS_ERROR: 
         _LATB4=1;
          return TRUE;           
         break;
        default:                       
            break;    }
    return FALSE;
} // USB_ApplicationEventHandler

int main(int argc, char** argv) {
    // Initialize the processor and peripherals.   
    if ( InitializeSystem() != TRUE )    {       
          while (1);    }                 //Stay here  
    if ( USBHostInit(0) == TRUE )    {
        _LATB5 = 1;  
    }   
   else   
  {       
   while (1);       //Stay here   
  }
     while(1){                                 //Infinite cicle
              USBHostTasks();            //USB state machine
             _LATB7=_JSTATE;           //Monitorying the state of the bus
             _LATB8=_SE0; 
        }
    return (EXIT_SUCCESS);}

 
The results when the device is conected, is JSTATE=1, SE0=0, but the 'U1IRbits.ATTACHIF' interrupt is never activated, and the Stack stay machine stay in the STATE_DETACHED and SUBSTATE_WAIT_FOR_DEVICE.
 
Any idea about what could be the problem?  Something is missing in my "test code"?
Thanks. 

Attached Image(s)

#1

7 Replies Related Threads

    shinds_
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/10/25 16:09:38
    • Location: 0
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 05:03:23 (permalink)
    0
    Excuse me, friend.
     
    It's 2018 but I've got the same problem you did back then.
    I'm using p24FJ256GB106, but the problem sounds exactly the same.
     
    Did you ever find a solution? 
    #2
    Jim Nickerson
    User 452
    • Total Posts : 5842
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 06:42:05 (permalink)
    0
    shinds_
    Excuse me, friend.
     
    It's 2018 but I've got the same problem you did back then.
    I'm using p24FJ256GB106, but the problem sounds exactly the same.
     
    Did you ever find a solution? 


    I wonder if you mornoticed the date on his post ?
    Not to mention he has not logged on to the forum since 2012
     
    edit: typo
    post edited by Jim Nickerson - 2018/10/30 08:01:13
    #3
    shinds_
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/10/25 16:09:38
    • Location: 0
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 07:08:08 (permalink)
    0
    Yeah, I did. Figured it was worth trying, since I'm unable to find a solution.
    #4
    Jim Nickerson
    User 452
    • Total Posts : 5842
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 07:24:26 (permalink)
    0
    Have you opened a support ticket at https://support.microchip.com 
    #5
    shinds_
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/10/25 16:09:38
    • Location: 0
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 07:35:29 (permalink)
    +1 (1)
    Nope!
    New here. As you probably realize.
     
    Thanks for the tip!
    #6
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 07:49:49 (permalink)
    0
    JANickerson
    Have you opened a support ticket at https://support.microchip.com 


    simillar issue, it's been almost two months with no answer :) maybe i should try to raise a ticked with my work email? don't want to because it's for a personal project..
    #7
    Jim Nickerson
    User 452
    • Total Posts : 5842
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: USB Interrupts and Attach Detection 2018/10/30 08:02:16 (permalink)
    0
    I have seen no differentiation with support for personal/work projects.
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5