
 Originally Posted by 
Darrel Taylor
					 
				 
				To: Demon and mister_e,
Hey, did you guys ever figure out the USB with DT_INTs approach.
I was thinking about trying a USB project, and wondered if you 2 ever got it working?
<br>
			
		 
	 
 Well, i hate to say that Darrel but something goes bad when using instant interrupt and USB.  Maybe some PBP variable need to be saved or something like that.
Bellow is a short and sweet working example using ON INTERRUPT to do the USBSERVICE each 100uSec.
OK it doesn't do anything else than sitting there and spin but, it keeps the connection alive without any Windows Warning.  Once this solve, it should fix USBOUT and USBIN... or help to 
It use a PIC18F4550 and a 4MHZ crystal OSC.
	Code:
	asm
    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                            ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                            ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                            ; No prescale (4 MHz oscillator input drives PLL directly)
    __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                            ;                  ;               ; Oscillator Switchover mode disabled
                            ;                  ; Fail-Safe Clock Monitor disabled
                            ; XT oscillator, PLL enabled, XT used by USB
    __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
    __CONFIG    _CONFIG2H, _WDT_OFF_2H 
    __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
endasm
DEFINE OSC 48          
PORTB   =   0
TRISB.0 =   0
LED0    VAR PORTB.0
TMR0IF  VAR INTCON.2
TMR0ON  VAR T0CON.7
INTCON  =   %10100000       ' Enable global and TMR0 interrupts
T0CON   =   %10000000       ' TMR0, CLK internal, prescaler 1:2, T0ON
UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
Reload      con 65000       ' ~100 uSec
ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB
goto SkipMacro
    asm 
Reload_TMR0 macro
    BCF     _TMR0ON         ; stop timer
    MOVE?CW _Reload,TMR0L   ; reload
    BCF     _TMR0IF         ; clear overflow flag
    BSF     _TMR0ON         ; start timer
    ENDM
    endasm
SkipMacro:
    pause 500               ' Settle delay
    usbinit                 ' initialise USB...
@   Reload_TMR0             ; Reload timer0
    ON INTERRUPT GOTO DoUSBService
Start: 
    goto start              ' Spin 'till you die!
DISABLE
DoUSBService:
    toggle LED0             ' toggle LED each time 
    usbservice              ' keep connection alive
@   Reload_TMR0             ; reload timer
    RESUME                  ' getout of here
ENABLE
 So nothing complicated... just spinning and keep USB connection alive.
NOW, if i use the DT interrupt, IT SHOULD looks like this
	Code:
	asm
    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                            ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                            ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                            ; No prescale (4 MHz oscillator input drives PLL directly)
    __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                            ;                  ;               ; Oscillator Switchover mode disabled
                            ;                  ; Fail-Safe Clock Monitor disabled
                            ; XT oscillator, PLL enabled, XT used by USB
    __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
    __CONFIG    _CONFIG2H, _WDT_OFF_2H 
    __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
endasm
DEFINE OSC 48          
PORTB   =   0
TRISB.0 =   0
LED0    VAR PORTB.0
TMR0IF  VAR INTCON.2
TMR0ON  VAR T0CON.7
INTCON  =   %10100000       ' Enable global and TMR0 interrupts
T0CON   =   %10000000       ' TMR0, CLK internal, prescaler 1:2, T0ON
UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
Reload      con 65000       ' ~100 uSec
ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB
INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
goto skipmacro
    ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler    TMR0_INT,  _DoUSBService,   PBP,  no
    endm
    INT_CREATE               ; Creates the interrupt processor
Reload_TMR0 macro
    BCF     _TMR0ON         ; stop timer
    MOVE?CW _Reload,TMR0L   ; reload
    BCF     _TMR0IF         ; clear overflow flag
    BSF     _TMR0ON         ; start timer
    ENDM
    endasm
SkipMacro:
    pause 500
    usbinit ' initialise USB...
@   Reload_TMR0
@   INT_ENABLE  TMR0_INT
Start: 
    goto start        
DoUSBService:
    toggle led0
    usbservice
@   Reload_TMR0
@   INT_RETURN
 Right or i screw something?  Anyways ON both, the LED work as expected (so i shouldn't be too wrong) but, the second lost the USB connection really soon... and yeah you have to reboot or it will reboot for you if you disconnect
the USB plug.  It's getting boring 
i attach everything i have in my C:\PBP_PROG\USBDemo folder, including a compiled VB utility to monitor if the device is Connected or Not when using EasyHID default VendorID and ProductID
<img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1300&stc=1&d=116748409  1">
So for now, i still use the On Interrupt... Before i read and understand the whole Jan Axelson book, and build my own USB macros, i may need much spare time... oh yeah it's more than a RS-232 and there's a lot of improvements and adds to do with PBP.
Now the weird stuff... Melabs didn't include the 'interesting' registers like UCFG, UIR,UIE,UEIR,UEIE and probably others... bah xxx VAR BYTE EXT fix it for now and if needed.
To be honest, i didn't search really hard to find the problem source... getting lazy i guess :-)
				
			
Bookmarks