USBSERVICE + serout2 problem


Closed Thread
Results 1 to 40 of 52

Hybrid View

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

    Default

    > May I ask what drives the USBSERVICE interrupt?
    The USB module itself generates many different interrupts.

    > Also I would like to use DT_INTS-18.bas in the program as well
    > but I don't understand how to use the interrupt hook handler,
    > and could not find any example of it.

    That is not possible with USB_ASM_Service.pbp.
    All interrupts used with the "Hook" can only be ASM (assembly language) type interrupts.

    > Or... is there a way to turn DT_HID260 into a DT_CDC260?
    No, but I could write a DT_CDC program. If I ever get my computers and internet access at home.
    DT

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Ok, that was my understanding of the interrupt hook handler. Hmmm that will make things more difficult. A DT_CDC would be extremely helpful in my case, but that is a lot to ask...

    I will think about it, currently I have two different application, both that need to use the CDC profile (HID could work, but that would make programming more difficult on the computer side... also it is nice to use a terminal to drive the device without any dedicated software).
    One application needs Timer1 to do precise timing sampling, the second needs your multiple software PWM routine to drive 3 LEDs.

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

    Default

    aberco,

    Here's a little ditty that should get you going with servicing CDC and DT-INTS-18.
    Hope it helps.
    Code:
    DEFINE OSC 48
    
    INCLUDE "cdc_desc.bas"
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler     USB_INT,  _DoUSBSERVICE,   ASM,  yes
            INT_Handler     INT_INT,    _Handle_INT,   PBP,  yes
        endm
        INT_CREATE             ; Creates the Low Priority interrupt processor
    
        INT_ENABLE  USB_INT
        INT_ENABLE  INT_INT
    ENDASM
    
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
    
    ;----[Main program loop]----------------------------------------------------
    Main:
        ; some code here
    GOTO Main
    
    ;----[Interrupt handler -- Service USB]-------------------------------------
    DoUSBSERVICE:
          USBSERVICE                   ; Run the SERVICE routines
    @ INT_RETURN
    
    ;----[Interrupt handler -- INT]
    Handle_INT:
     ; something here
    @ INT_RETURN
    DT

  4. #4
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Thanks Darrel, I will play with this in a couple of days, it looks like this would do the trick.

    What I really like in your DT_HID260 is that all USB dependent declaration are clearly listed within the program. I feel it is better and self-contained than digging cdc_desc.bas to modify the values, but maybe it works just the same at the end. I am now planning to use a bootloader as well, so I will have to check if two independent USB setup can be used one after the other without creating conflict.
    Last edited by aberco; - 22nd September 2010 at 18:00.

  5. #5
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Well I must say that I'm still banging my head against USB CDC... I've tried this, the led does blink for 1 1/2 cycles and everything hangs and the pic does not enumerate.
    Now, is it because USB is serviced before the device is attached?

    I changed the interrupt from "ASM" to "PBP" (USBSERVICE is a PBP instruction).

    Code:
    '*******************************************************
    'Config fuses for PIC18LF14K50
    '*******************************************************
    
    ASM
    CONFIG CPUDIV=NOCLKDIV ; CPU runing at full speed
    CONFIG USBDIV=OFF ; Low speed USB clock diviser disabled, not used here
    CONFIG FOSC=HS ; Use of High Speed crystal oscillator
    CONFIG PLLEN=ON ; Enable PLL multiplier, 12Mhz oscilator x 4
    CONFIG PCLKEN=ON ; Primary clock source is enabled
    CONFIG FCMEN=OFF ; Failsafe clock off
    CONFIG IESO=OFF ; Oscillator switchover mode disabled
    CONFIG WDTEN=ON ; Watchdog timer on
    CONFIG WDTPS=512 ; Watchdog divider is 512
    CONFIG MCLRE=OFF ; Disable MCLR pin, enable RC3
    CONFIG STVREN=ON ; Stack full/underflow will cause reset
    CONFIG LVP=OFF ; Low voltage programming disabled
    CONFIG BBSIZ=OFF ; 512kW block boot size
    CONFIG XINST=OFF ; Extended instruction mode disabled
    ENDASM
    
    
    DEFINE OSC 48          
    DEFINE LOADER_USED 1
    
    '*******************************************************
    'Init for PIC18LF14K50
    '*******************************************************
    
    'Set ADC pins to digital operation
    ADCON0 = %00000000 'turn ADC OFF
    CM1CON0 = %00000000 'disabling comparator module 1
    CM2CON0 = %00000000 'disabling comparator module 2
    
    'Define pin function
    TRISA = %00000000 'PortA all digital output
    TRISB = %00000000 'PortB all digital output
    TRISC = %00000000 'PortC all digital output
    
    ANSEL = %00000000 'Disable analog input all pins
    ANSELH = %00000000 'Disable analog input all pins
    
    RedLED VAR PORTC.3
    
    INCLUDE "cdc_desc.bas"
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler     USB_INT,  _DoUSBSERVICE,   PBP,  yes
        endm
        INT_CREATE             ; Creates the Low Priority interrupt processor
    
        INT_ENABLE  USB_INT
    ENDASM
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
    
    ;----[Main program loop]----------------------------------------------------
    Main:
    HIGH RedLED
    PAUSE 200
    LOW REDLED
    PAUSE 200
    GOTO MAIN
    
    ;----[Interrupt handler -- Service USB]-------------------------------------
    DoUSBSERVICE:
          USBSERVICE                   ; Run the SERVICE routines
    @ INT_RETURN
    
    END

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

    Default

    Try moving the USB enable to after the initialization.

    Code:
    ;    INT_ENABLE  USB_INT
    ENDASM
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
    @ INT_ENABLE  USB_INT
    Enabling before USBINIT probably wasn't a good idea on my part.

    And while USBSERVICE is a PBP statement, the code is all ASM and does not use any of PBP's system variables. So change it back to ASM "type".
    DT

  7. #7
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Hmm that make sense... I made the changes but that doesn't work any better though.

    A little troubleshooting, if I plug the USB connector halfway (just Power) the LED blink, however it stops a couple 100's ms after D+/D- get connected.

Members who have read this thread : 1

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