Page 1 of 1

Adapting Code for the 1-Key Keyboard

Posted: Mon Apr 04, 2011 7:07 pm
by Eptheta
I have basic experience with the Atmega series of microcontrollers(simple IO, timers, interrupts, PWM) and wanted to try this project out:
http://blog.flipwork.nl/?x=entry:entry081009-142605

I wanted(for experimental and learning purposes) to use this code on an Atmega32 instead of the Attiny85 suggested in the blog.
Please tell me what I should look out for while editing and compiling the code.

Here is a list of things that I think need to be changed in the source code so that it will work:
1. In usbconfig.h, I changed the code to:

Code: Select all

#define USB_CFG_IOPORTNAME      D
#define USB_CFG_DMINUS_BIT      0
#define USB_CFG_DPLUS_BIT       2 //because INT0 on the mega32 is PinD2

Anything else in usbconfig.h?

2.In main.c

Code: Select all

static void timerInit(void)
{
    TCCR1 = 0x0b;           /* select clock: 16.5M/1k -> overflow rate = 16.5M/256k = 62.94 Hz */
   
}


which is just setting the prescaler at CK/1024, so I thought I could do the same with TCCR1B= 5; // to set CS12 and CS10 (clk/1024)
for the Atmega32

3. My Atmega32's fuse bits have already been set for high frequency external crystal and I have both a 16Mhz and 12Mhz crystal. (I read that I can use either?)


Are there any other things I should be careful of while changing the code ?

Thank you.

Re: Adapting Code for the 1-Key Keyboard

Posted: Wed Apr 13, 2011 1:43 am
by Alan Chatham
I also posted this reply on Adafruit, but here it is again:

So, in my experience, V-USB is great, but kind of a bear to work with/get set up with. My personal recommendation would be to get up and running with the HID mouse example they've got at the V-USB site - I think that's the easiest to understand, easiest to test if it's working project out there. The 1-key keyboard project you've got there is a little more tricky since it uses the internal oscillator option, and it might actually be using the PLL clock option that's unique to the ATtiny line. Regardless, using a crystal just makes for one less thing that can go wrong when using V-USB, and there are a lot of little things that can go wrong.

The big changes you'll need to make will be changing the pin definitions like you did and then changing the makefile. You'll need to make sure that you're choosing the right chip, and then choosing the proper clock speed. That clock speed is important - since V-USB is written in assembly that's tuned for specific clock frequencies, the compiler needs to know which speed of the library it needs to use.

Once you can get connectivity working with a really basic example, it's generally pretty easy to go in and change the VID/PID, USB descriptor, and main loop to reflect that you want a keyboard, not a mouse.

What development system are you using? There are a couple more caveats if you're using AVR Studio, but I generally find it to be easier, and if you're using it, I can give you some more pointers.

Hope it helps!