Easy HID Command -Response application


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1

    Default

    Where should this go?

    I cut'n'pasted from the above code section, into microcodestudio, then added this to the top, before the define

    Code:
    ' **************************** Added from other demo
    buffer	Var	Byte[16]
    cnt	Var	Byte
    LED	Var	PORTB.0
    Define  OSC 48
    '****************************************************
    
    high led


    Then at the bottom after overusbservice I added the usb in/out and a led flash to show its alive

    Code:
    idleloop:
    
        low led
        pause 500
        high led
        pause 500
    
    	cnt = 16	' Specify input buffer size
    	USBIn 3, buffer, cnt, idleloop
    
    ' Message received
    
    	buffer[0] = "H"
    	buffer[1] = "e"
    	buffer[2] = "l"
    	buffer[3] = "l"
    	buffer[4] = "o"
    	buffer[5] = " "
    	buffer[6] = "W"
    	buffer[7] = "o"
    	buffer[8] = "r"
    	buffer[9] = "l"
    	buffer[10] = "d"
    	buffer[11] = 13
    	buffer[12] = 10
    	buffer[13] = 0
    
    outloop:
    	
        USBOut 3, buffer, 14, outloop
    
    	Goto idleloop	' Wait for next buffer
    usbinit and usbservice was removed from the code of the other demo like it says to.

    It looks to me like a worker, but i get compile errors, lots of them

    This one

    Code:
    IDLEIF             VAR UIR.4         ; USB Idle Interrupt Flag
    <
    gives me a bad datatype (first of a few)

    and this one

    Code:
        UIE = $7F                    ; enable USB interrupts
    throws up a syntax error with some more below it


    I tried it as

    INCLUDE "USB_ASM_Service"

    At the top of my little test and MCS opened it as a 2nd page, and threw up the same errors.

    Just for completeness thats here
    Code:
    include "USB_ASM_Service.pbp"
    
    ' **************************** Added from other demo
    buffer	Var	Byte[16]
    cnt	Var	Byte
    LED	Var	PORTB.0
    Define  OSC 48
    ' ****************************************************
    
    high led
    
    idleloop:
    
        low led
        pause 500
        high led
        pause 500
    
    	cnt = 16	' Specify input buffer size
    	USBIn 3, buffer, cnt, idleloop
    
    ' Message received
    
    	buffer[0] = "H"
    	buffer[1] = "e"
    	buffer[2] = "l"
    	buffer[3] = "l"
    	buffer[4] = "o"
    	buffer[5] = " "
    	buffer[6] = "W"
    	buffer[7] = "o"
    	buffer[8] = "r"
    	buffer[9] = "l"
    	buffer[10] = "d"
    	buffer[11] = 13
    	buffer[12] = 10
    	buffer[13] = 0
    
    outloop:
    	
        USBOut 3, buffer, 14, outloop
    
    	Goto idleloop	' Wait for next buffer
    Last edited by f_lez; - 1st November 2009 at 17:05.

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

    Default

    Looks like you've been busy while I was sleeping.

    PBP 2.46 was missing a few registers in the PIC18EXT.bas file.
    You can either add these lines to that file, or place them at the top of your program (before the INCLUDE file).
    Code:
    UIR  VAR BYTE EXT
    UIE  VAR BYTE EXT
    UEIE VAR BYTE EXT
    UEIR VAR BYTE EXT
    For the _config depricated warning you can add w = -230 to the 18F2550.inc file ...
    Code:
            LIST p = 18F2550, r = dec, w = -311, w = -230, f = inhx32
    hth,
    DT

  3. #3

    Default

    thanks that was just the little gem of info i was missing!

    And it works!

  4. #4

    Default

    Simple code in a loop...

    Code:
    ' Main Program Loop
    Loop:
     
        USBOut 3, Buffer, Cnt, loopy
    loopy:
        porta=170 ' fancy led pattern0
        pause 500
        porta=85  ' fancy led pattern1
        pause 500
    
        goto loop
    end
    After about 30 minutes, stops running......

    Pic is stable etc had it running 24hrs+ on a simple led flasher. (on same dev board)

    any guesses?
    Last edited by f_lez; - 28th February 2010 at 19:54.

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

    Default

    Well, it's a Total guess but ...

    Try adding a USBIN statement to the loop.
    If anything comes in, and the SIE doesn't get released, everything locks up (including the PC application).

    The reason I say it's a guess is because it requires recieved data.
    If you are using HyperTerminal then you would need to type something to have it happen.

    DT

  6. #6

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Well, it's a Total guess but ...

    I dopnt know whats going on TBH, I watched it fail after about 30 mins, twice, I saw it fail after ten, I gave up hitting my head and posted the above, and then left it running, 2hrs later it was still running, I went to bed, got up this morning, still running, I went out for a few hours, come back, still running....

    I can only guess something upset the pic at an hardware level because i have changed nothing at the software level. (I have even glued the crystal to the crystal socket!)

    Anyhow.... these nuggets..

    Plugged indicates when the device is fully connected to the PC.
    RX_READY indicates when a report has been received.
    TX_READY indicates when it's OK to Send. The device is Plugged and the SIE is ready to accept data.
    Do you an an example line for those?

    Once upon a time getting data into the pic was fairly easy, now I have to keep the pic doing some monitoring of its io pins but at same time accepting commands from the fake comport, so seeing if any data was waiting, as it seems to have very little in the way of flow control would be useful. (what happened to the wonderful buffers and fifo's on real hardware!)

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

    Default

    Gremlins, or maybe the cats (if you have any).

    Make sure you have plenty of capicitance on the VUSB pin. (.22uF to .47uF)
    And have both a 10uF and 0.1uF capacitors on the Power Rails (VSS-VDD).

    Plugged, RX_READY and TX_READY are just normal "Bits".

    RX_READY indicates that data has been received. It should be cleared after use.
    Code:
    Main:
        IF RX_READY THEN        ; USB data has been rcvd
            RX_READY = 0        ; clear the Ready flag
            USBIN 1, Buffer, Cnt, Main
            LCDOUT $FE,1,STR Buffer
        ENDIF
    TX_READY indicates that the device is plugged in and the SIE is ready to accept data to send.
    Code:
        IF TX_READY THEN         ; USB is Ready to transmit
            TX_READY = 0         ; clear the Ready flag
            ADCIN 0, ADval
            ARRAYWRITE Buffer,[DEC4 ADval," "]
            USBOUT 1, Buffer, Cnt, TXfail
          TXfail:
        ENDIF
    GOTO Main
    DT

Similar Threads

  1. USB hid maker help please.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2013, 15:49
  2. i cant get 18f2550 work as HID
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 13th October 2009, 17:39
  3. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 12:55
  4. Hid Maker FS Problems
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2009, 22:27
  5. Making your own HID descriptor file
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th April 2005, 13:35

Members who have read this thread : 0

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