USBSERVICE + serout2 problem


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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.

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

    Default

    I may have asked you this in another thread, sorry if I did ... but ...

    What size capacitor do you have on VUSB.
    0.22 - 0.47uF?
    DT

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

    Default

    Hardware is fine, USB does work with DT_HID260. I have two prototype boards with 220nF, both are ok. Config fuses are OK too, should be software-related.
    Last edited by aberco; - 7th October 2010 at 10:21.

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

    Default

    Well, I've got a 14K50 here now, and it enumerates and holds the USB just fine.
    So far I haven't got a single blink out of RC3 yet though.

    Not sure what's going on there, but I'll play with it some more tomorrow.

    I'll add some USBIN/USBOUT statements too and make sure CDC is really working.

    What operating system are you using?
    Win7-64 here.
    DT

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

    Default

    Well yeah, you're right! it does enumerates!!! and it even blink on my application.

    What's happening, this is due to my programming setup and the specific hardwiring of the 18F1xK50. The USB lines D+/D- are shared with PGD and PGC, and it seems that in order for USB to work, the programmer has to be disconnected. For this purpose, I have purchased microchip special module for the 18F1xK50, that adapt the programming levels of the programmer to something that the PIC can accept, but at the same time allows to leave plugged the USB cable of the host computer by protecting the D+/D- lines from programming voltages.

    Well I realized early on that it did not work, and I had to disconnect PGD and PGC in order to have USB working, so I added a set of switches on my programming cable.

    Now I've been able to verify different behavior on USB programs, especially DT_HID260 which is the only one "powerful" enough to enumerate even with PGD/PGC connected to the programmer. All others required those lines disconnected to enumerate.



    Now, about your little CDC routine, it does work well with PGD/PGC disconnected. But when I connect them back the USB connexion drops and the PIC crashes. No big deal, but I'll have to make sure that communication is established when servicing, and especially turn it of before unplugging USB.

    Now I'll try to add USBIN/USBOUT statements and play a bit with communication before building the full program around it. Thanks for your great help!
    Last edited by aberco; - 8th October 2010 at 13:09.

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