USB HID Keyboard

Post here if you want to announce new wiki modules, projects or articles

Moderators: David Barker, Jerry Messina

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

USB HID Keyboard

Post by RangerBob » Mon Feb 02, 2009 4:33 pm

Just to let everyone know, I've put up a demo for using swordfish as a USB HID Keyboard on the wiki.

Hope this helps someone! Any feedback is welcome!

Nathan

Toley
Posts: 32
Joined: Tue Nov 20, 2007 5:47 pm
Location: Canada

Post by Toley » Mon Feb 02, 2009 10:44 pm

Thank you very much Nathan. I've tried to do that for a long time without success.

Finally my home made guitar hero will work ;)

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Tue Feb 03, 2009 9:18 am

Glad to be of help!

Good luck with that! I'd like to see the results. Are you planning on working with frets-on-fire?

PS. I updated the example when I realised how simple it was to read back the LED status (ie. CapsLock, NumLock, etc), if that helps.

PPS. And I couldn't resist adding more functionality, such as opening its own wordpad instance! ;)

Toley
Posts: 32
Joined: Tue Nov 20, 2007 5:47 pm
Location: Canada

Post by Toley » Wed Feb 04, 2009 2:59 am

I have an old Playstation2 Guitar that don't work anymore. I had plan to modify it and to make it a PC-USB guitar. I didn't had no trouble with the hardware but the software never worked like I want.

First things first, I have to go back to the beginning. I've ever try Microchip FS USB but it's been a while and it was with PDS. I don't really remember how to use it.

Do you have a link that can help me getting started with FS USB and Swordfish?

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Wed Feb 04, 2009 10:01 am

Hello Toley,

I don't really have any links, but I promise you the USB integration for swordfish is top notch. The Help file is very self explanatory and the examples are very flexible to base your own work off of.

My suggestion would be to just get out your PICDEM FS USB board and have a play around with this example code, and the example code from the Swordfish USB folder. The EasyHID creator is also worth playing with as it does make creating your own HID profiles very easy.

Make sure your FSUSB Board still has the default USB bootloader, compile the example code, and bootload it using the microchip PICDEM FS USB Demo Tool. Really easy to play around then. You won't screw anything up too badly doing this (although I did temporarily brick my iPhone whilst creating the Keyboard demo! It tried to update its firmware whilst I was accidentally sending dud data. Doh!).

If you have any questions post them to the forum, and I'm sure you'll get some replies, even if they are just from me!

Good luck with your project, I think I might start scouting around for a broken guitar hero guitar too now!

Nathan

jchandir
Posts: 10
Joined: Wed Apr 08, 2009 12:09 am

Help

Post by jchandir » Wed Apr 08, 2009 12:17 am

I have been trying to compile the HID keyboard sample but I keep getting some errors. Can someone tell me why i am getting these errors. I have copied the files needed from the web page and saved them in the user library but I still get errors. I am kinda new to swordfish so please forgive me if its a stupid question. Thank you

hidkeyboard.bas: Identifier not declared: TXReportRAM
hidkeyboard.bas: Identifier not declared: RXReportRAM

..and about 10 more errors similar to these. Please let me know. thank you

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Wed Apr 08, 2009 7:49 am

Which device are you trying to compile for?

It needs to be a 18F2455, 18F2550, 18F4455 or 18F4550 which have the USB extended dual port ram, the error is stating that the USB ram buffers have not been declared, which normally occurs automatically on these devices.

I recommend a 18F4550 to start with as this is the device I have tested the code on.

If you need it to work on a 18F87J50 you will need my modified USB routines, you'll find them posted on the wiki too.

Are you trying this on the SE demo edition? If so then all bets are off i'm afraid. I understand that USB cannot be used in the SE demo edition due to the (fairly generous) RAM limitations. I haven't tried it myself so YMMV.

I'm afraid I will be offline for a while after this, if you post and I don't get back to you for a while, it's nothing personal! I'm sure others will try to help too, don't let it put you off!

Nathan

jchandir
Posts: 10
Joined: Wed Apr 08, 2009 12:09 am

Post by jchandir » Thu Apr 09, 2009 12:06 am

I am using a 18f4550 and I am not using the demo. I have bought a copy of the SF license. I still cannot get it to compile no matter what I do. Thanks for the fast reply..

jchandir
Posts: 10
Joined: Wed Apr 08, 2009 12:09 am

Post by jchandir » Sat Apr 11, 2009 5:03 pm

Sorry, i figured it out, i didn't give the modules the right name.. sorry stupid mistake.

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Mon Apr 20, 2009 10:11 am

Ok, good to hear!

tomasoft
Posts: 3
Joined: Wed Aug 19, 2009 8:34 am

Simulation of your code to PROTEUS?

Post by tomasoft » Wed Aug 19, 2009 8:40 am

Hello!, i now the thread is a little old, but i just found it and while i can compile the code succesfully, when i load the hex file that swordfish produces, to the picdem fs usb board - that proteus has included in it's samples - i get the error "PIC18 STACK pc=0x1460 stack overflow is forcing device reset."

Any help would be really appreciated!

Tom.

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Wed Aug 19, 2009 10:19 am

Hello Tom,

I've never tested on Proteus before, but the specific bug you're referencing is due to the bootloader offset at the beginning (ie. you don't have a bootloader and the ISIS doesn't like it!). You can stop this by commenting out the line:

Code: Select all

// Use with FSUSB Bootloader
#option org_reset = $0800
However I am unsure of how good the virtual USB/HID profile is on ISIS as although the device enumerates with windows as a HID device, the program sits waiting indefinitely waiting for the HID.attach. If you comment this out, it goes through the motions but does not seem to communicate at all.

I do not know where this is coming from, but let me assure you, on real hardware this does work! If you get any results in your testing please let me know and i'll amend this.

Nathan

tomasoft
Posts: 3
Joined: Wed Aug 19, 2009 8:34 am

Post by tomasoft » Wed Aug 19, 2009 2:39 pm

To tell you the truth the mcu no longer stack resets but after it has some problem with the descriptor...

tomasoft
Posts: 3
Joined: Wed Aug 19, 2009 8:34 am

Testing with real hardware

Post by tomasoft » Sun Sep 27, 2009 5:11 pm

Hello Again.
I have easypic5 and 18f4550 i have also commented the bootloader line.
The rd.0 led lights but nothing else happens.
Any ideas? I cannot even see the device in the device manager. I use PICFLASH to program the pic and i get no errors during the process. The only change i have done is change the xtal in the programmer from 20MHz to 8MHz couse this is the actual frequency.

Any ideas?

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Post by RangerBob » Mon Sep 28, 2009 9:52 am

Hello Tom,

When you say you changed the "crystal in the programmer", do you mean the main system crystal? If so, when you changed the Crystal, did you change the config settings to reflect this?

The USB block of the IC only runs at 2 speeds, 6MHz (for low Speed USB) or 48Mhz (for High Speed USB - the one we use). If you changed the crystal without changing the config bits then the timings will be all wrong.

Looking at page 32 of the datasheet (OSCILLATOR CONFIGURATION OPTIONS FOR USB OPERATION), I think you'll need to change the Config bits to:

Code: Select all

Clock = 48

// 8Mhz crystal, 48Mhz internal (FS USB)
Config
   PLLDIV = 2,         // Change this one
   CPUDIV = OSC1_PLL2,
   USBDIV = 2,
   FOSC = HSPLL_HS,
   VREGEN = ON
This means that your processor clock will still be running at the Main USB clock speed of 48 MHz, and the USB block gets what it needs.

The PLLDIV you changed divides the Main crystal oscillator down to a target of 4 MHz for feeding the 96 MHz PLL (page 26), which then gets divided-by-2 for our target 48MHz.
For a 20 Mhz input, this is a divide-by-5, for 8 MHz input its a divide-by-2.

I think this will work but cannot check right now as I am not with a board. If not hopefully this should put you on the right track! If not, can you exchange the crystal for a 20MHz?

Best Regards,

Nathan

Post Reply