i cant get 18f2550 work as HID


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    30

    Default i cant get 18f2550 work as HID

    Hi every body

    i m trying to blink some leds with pic 18f2550 using usb connection to my labtop

    i have some problems

    1- when i open vb2008 interface, it doesnt identify that usb is plugged untill i touch Vusb with my hand. i aready put 200nf capacitor to ground on Vusb. i is very strange.

    2- when i send data to pic, i doesnt blink the leds. i revised vb code many times. and i revised my controller code also. i just cant find what is wrong.

    plz help me. it driven me crazy. espicially when it needs my to provide a path to ground with my body on Vusb!!!

    pic code

    Code:
    DEFINE OSC 48          
    
    USBBufferSizeMax   con 8  ' maximum buffer size
    USBBufferSizeTX    con 8  ' input 
    USBBufferSizeRX    con 8  ' output
    
    ' the USB buffer...
    USBBuffer        Var Byte[USBBufferSizeMax] 
    USBBufferCount   Var Byte 
    
    ' ************************************************************
    ' * main program loop - remember, you must keep the USB      *
    ' * connection alive with a call to USBService every couple  *
    ' * of milliseconds or so...                                 *
    ' ************************************************************
    usbinit ' initialise USB...
    ProgramStart:
        USBBUFFER[0] = 0
        USBBUFFER[1] = "P"
        USBBUFFER[2] = "="
        USBBUFFER[3] = 15
        USBBUFFER[4] = "T"
       gosub DoUSBOut 
       gosub DoUSBIn
        
       portb = usbbuffer[3]
        
       
       goto ProgramStart  
    
    ' ************************************************************
    ' * receive data from the USB bus                            *
    ' ************************************************************
    DoUSBIn:
       USBBufferCount = USBBufferSizeRX              ' RX buffer size
       USBService                                    ' keep connection alive
       USBIn 1, USBBuffer, USBBufferCount, DoUSBIn   ' read data, if available
       return
        
    ' ************************************************************
    ' * wait for USB interface to attach                         *
    ' ************************************************************
    DoUSBOut:
       USBBufferCount = USBBufferSizeTX              ' TX buffer size
       USBService                                    ' keep connection alive
       USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
       return
    vb code
    Code:
    Public Class frmUSB
        ' vendor and product IDs
        Private Const VendorID As Short = 4660    'Replace with your device's
        Private Const ProductID As Short = 1      'product and vendor IDs
    
        ' read and write buffers
        Private Const BufferInSize As Short = 8 'Size of the data buffer coming IN to the PC
        Private Const BufferOutSize As Short = 8    'Size of the data buffer going OUT from the PC
        Dim BufferIn(BufferInSize) As Byte          'Received data will be stored here - the first byte in the array is unused
        Dim BufferOut(BufferOutSize) As Byte    'Transmitted data is stored here - the first item in the array must be 0
    
        ' ****************************************************************
        ' when the form loads, connect to the HID controller - pass
        ' the form window handle so that you can receive notification
        ' events...
        '*****************************************************************
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' do not remove!
            ConnectToHID(Me)
            Label2.Text = "Connected to HID"
        End Sub
    
        '*****************************************************************
        ' disconnect from the HID controller...
        '*****************************************************************
        Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            DisconnectFromHID()
        End Sub
    
        '*****************************************************************
        ' a HID device has been plugged in...
        '*****************************************************************
        Public Sub OnPlugged(ByVal pHandle As Integer)
            If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
                ' ** YOUR CODE HERE **
                Label2.Text = " USB plugged"
    
            End If
        End Sub
    
        '*****************************************************************
        ' a HID device has been unplugged...
        '*****************************************************************
        Public Sub OnUnplugged(ByVal pHandle As Integer)
            If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
                hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
                ' ** YOUR CODE HERE **
                Label2.Text = "USB unplugged"
    
            End If
        End Sub
    
        '*****************************************************************
        ' controller changed notification - called
        ' after ALL HID devices are plugged or unplugged
        '*****************************************************************
        Public Sub OnChanged()
            ' get the handle of the device we are interested in, then set
            ' its read notify flag to true - this ensures you get a read
            ' notification message when there is some data to read...
            Dim pHandle As Integer
            pHandle = hidGetHandle(VendorID, ProductID)
            hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
        End Sub
    
        '*****************************************************************
        ' on read event...
        '*****************************************************************
        Public Sub OnRead(ByVal pHandle As Integer)
            ' read the data (don't forget, pass the whole array)...
            If hidRead(pHandle, BufferIn(0)) Then
                ' ** YOUR CODE HERE **
                TextBox2.Text = Str$(BufferIn(3))
                Label2.Text = "Data recieved"
                ' first byte is the report ID, e.g. BufferIn(0)
                ' the other bytes are the data from the microcontroller...
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            End
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            BufferOut(0) = 0                    'first byte is always the report ID
            BufferOut(1) = Asc("P")             'first data item
            BufferOut(2) = Asc("=")             'second data item
            BufferOut(3) = Val(TextBox1.Text)   'third data item to be send ober usb
            BufferOut(4) = Asc("T")             'fourth data item
            'write the data, dont forget to send the whole array
            hidWriteEx(VendorID, ProductID, BufferOut(0))
            hidWriteEx(VendorID, ProductID, BufferOut(1))
            Label2.Text = "Data sent"
    
        End Sub
    End Class

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


    Did you find this post helpful? Yes | No

    Default

    Have you ENABLED the USB voltage regulator in the Configs?

    _VREGEN_ON_2L
    <br>
    DT

  3. #3
    Join Date
    Oct 2009
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    hi

    yeah i did activated internal voltage regulator. he is a pic for fuse configuration in my programmer. it shows what i used
    Attached Images Attached Images  

  4. #4
    Join Date
    Oct 2009
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    please help me

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default

    You yust should set USBPPL and PPLDIV to 48MHz, or divide by 12 if you use 48MHz resonator.
    I think that code is good.

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


    Did you find this post helpful? Yes | No

    Default

    Ahmadabuomar,

    Another possible problem ...

    According to your picture ...
    Low Voltage Programming (LVP) is Enabled.
    You could put a pull-down resistor on RB5/PGM, but you probably want to disable it completely since you are using the full PORTB in your program.

    And pedja089, you can't use a 48Mhz resonator with the 4550's.
    Maximum frequency using the main oscillator is 25Mhz.
    You can use an external TTL (canned) 48Mhz oscillator with EC mode.
    <br>
    DT

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. USB hid maker help please.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2013, 14:49
  3. Error 0X0000008E when connecting a 18F2550 USB HID
    By FranciscoMartin in forum USB
    Replies: 8
    Last Post: - 16th October 2008, 17:20
  4. 18f2550 + 24lc512
    By mpardinho in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th December 2007, 22:02
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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