USB 18F4550

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
E-Nawar
Posts: 7
Joined: 01 Jun 2011 16:44

USB 18F4550

#1 Post by E-Nawar » 01 Jun 2011 17:11

Hi everyone,
I'm trying to learn about communication between USB and 18f4550. I've been trying for five days now and windows found unrecognized device, this is as far as i got :(

All what I'm trying to do for now simply is to turn LED on/off via USB that's it.

I'm using:
MikroC PRO v4.6
C# for the application

:?: are there any books or already made projects i can learn from?

Thanks
E Nawar

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: USB 18F4550

#2 Post by tihomir.losic » 02 Jun 2011 14:50

Hello,

you have our official USB example in our compiler,
and I will also attach them here with this post.

For any further instructions, feel free to contact us.

Best regards,

Losic Tihomir
Attachments
HID Read Write Interrupt.rar
(9.76 KiB) Downloaded 643 times
mikroElektronika [Support team]

E-Nawar
Posts: 7
Joined: 01 Jun 2011 16:44

Re: USB 18F4550

#3 Post by E-Nawar » 02 Jun 2011 19:25

:D Thank you Losic Tihomir,
the code is working just fine and once I'm finished with the C# application i will reply to my post

Thanks
E Nawar

E-Nawar
Posts: 7
Joined: 01 Jun 2011 16:44

Re: USB 18F4550

#4 Post by E-Nawar » 06 Jun 2011 18:55

Please i need help!!!
Hi everyone, I tried the two examples of 18F4550 of MikroC PRO and both work. (HID Read Write Interrupt & HID Read Write Polling) after the Windows recognized the PIC, i tested it using HID Terminal in MikroC (tools >> HID Terminal >> Terminal tab)
i've send and received from/to the PIC

The circuit diagram:
capacitors 2x 22pF, 200nF, 0.1uf
resistors 470, 10K
Crystal Oscillator 8MHz
18f4550.jpg
18f4550.jpg (45.5 KiB) Viewed 5555 times
The project sittings:
Image1.jpg
Image1.jpg (39.34 KiB) Viewed 5555 times
Image2.jpg
Image2.jpg (37.76 KiB) Viewed 5555 times
the rest of the sitting are the same as the default sitting and the crystal should be 48MHz in the sitting (8MHz in circuit)

However,,,,,,, the PROBLEM is that i tried to rewrite the code of the example in a new project but it didn't work!!! i even used the same descriptor and i tried again with making a new descriptor didn't work. then i checked the examples' hex files and their size were about 16.6KB and the one i got after building the new project is 600bytes

then i tried to edit the example of MikroC itself and i build it and again i got 600Bytes hex file :(

did anyone face this problem before? how can i solve it? is there a mistake i'm making?

Thank you all
E Nawar

E-Nawar
Posts: 7
Joined: 01 Jun 2011 16:44

Re: USB 18F4550

#5 Post by E-Nawar » 07 Jun 2011 20:36

Hi everyone,
I used an older version of MikroC PRO and it worked!!!
maybe there is some problem with 4.6v

Thank you all
E Nawar

E-Nawar
Posts: 7
Joined: 01 Jun 2011 16:44

Re: USB 18F4550

#6 Post by E-Nawar » 18 Jun 2011 23:07

Hi everyone,
Finally finished with the PC application, now I'm able to communicate with theUSB BUT, not using Visual C# 2010 instead I used Visual Basic 2010 and it's working great!!

This is the best site where anyone can start making their own application to communicate with HID USB
http://helmpcb.com/software/usb-hid-tem ... comment-59

vincent_himpe
Posts: 23
Joined: 08 Jul 2011 19:20
Location: San Jose CA
Contact:

Re: USB 18F4550

#7 Post by vincent_himpe » 11 Jul 2011 23:59

DOes anyone have Vb code to talk HID natively ? I mean using the windows HID functions. I do not want to use a third party 'mystery' dll like mchid. ( there are licencing problems. I don't know if i can distribute that dll with a commercial product. )

fweinrebe
Posts: 28
Joined: 29 May 2008 13:22
Location: Namibia
Contact:

Re: USB 18F4550

#8 Post by fweinrebe » 13 Jul 2011 12:21

Did you check out the page of Jan Axelson http://www.lvr.com/winusb.htm? I used it when I started with the PIC18F4550 and MS C#.

It uses the native HID driver as found in Windows.
Fritz

Proud owner of EasyPic5, PICPLC16 V6, PIC32 MMB, PIC40 and registered mikroC PIC and PIC32 compiler.

vincent_himpe
Posts: 23
Joined: 08 Jul 2011 19:20
Location: San Jose CA
Contact:

Re: USB 18F4550

#9 Post by vincent_himpe » 23 Aug 2011 22:31

fweinrebe wrote:Did you check out the page of Jan Axelson http://www.lvr.com/winusb.htm? I used it when I started with the PIC18F4550 and MS C#.

It uses the native HID driver as found in Windows.
yeah. that is not understandable. that sample code tries to do everything at the same time... bulk , interrupt , threading .. overload !

all i need is a few simple routines :
- pull the list of devices , filtered on vid and pid ( there can be more than one attached ... )
- retrieve the descriptors for each device in the above list.
- Open a device based on vid/pid and desciptor parameter ( serial number ). return a handle to this device.
- Send an array of 64 bytes ( one HID packet) to the handle (this must be blocking)
- Raise an event when a packet is received , packet is available as a string or an array of byes.


for example :
public devicelist() as integer
public lastdevice as integer
Sub FindDevices(vid as uint32,pid as uint32) : this populates 'devicelist' and sets 'lastdevice'
end sub
function GetDescriptor (deviceid as integer) as string : this fetches the decriptors from a device in the list.
end function
function Opendevice (deviceid as integer)

so i can write code like this :

finddevices(myvid,mypid)
dim myfirstdevice as integer = OpenDevice(devicelist(1))
dim myseconddevice as integer = opendevice(devicelist(2))

writepacket (myfirstdevice,x)
blabla

It doesn;t need ot be harder than that

fweinrebe
Posts: 28
Joined: 29 May 2008 13:22
Location: Namibia
Contact:

Re: USB 18F4550

#10 Post by fweinrebe » 24 Aug 2011 08:48

Yeah I understand what you mean. I am using UsbLibrary at the moment which can be found at http://www.codeproject.com/KB/cs/USB_HID.aspx (Had to find the link again).

You can also try these:

http://www.icsharpcode.net/opensource/sharpusblib/

Then there is this one http://www.florian-leitner.de/index.php ... r-library/. Make sure you look at his Blog as well, there is some good info. It is at http://www.florian-leitner.de/index.php ... r-library/.

Hope it helps
Fritz

Proud owner of EasyPic5, PICPLC16 V6, PIC32 MMB, PIC40 and registered mikroC PIC and PIC32 compiler.

Post Reply

Return to “mikroC PRO for PIC General”