Page 1 of 1

HIDKeys converted to Attiny 2313 problems (understand C-code

Posted: Thu Aug 21, 2008 12:38 pm
by Ricke
Hi

I'm a beginner... that said I managed to convert and run the HIDKeys in an Attiny2313.

Problem is that I'm terrible at C.

I can successfully type A,B,C,D,E,F etc but the pin layout for Atmega8 and Attiny2313 differs so when I release the button I get QQQQQQQQQQQ.... - and that indicates PD7 key down (and that one dont even exist on a Attiny2313)

But I only neeed 8 keys instead of 17... so i was going to use PB0-PB7

I don't fully grasp the HIDKeys program... And tried and change this code:

Code: Select all

/* The following function returns an index for the first key pressed. It
 * returns 0 if no key is pressed.
 */
static uchar    keyPressed(void)
{
uchar   i, mask, x;

    x = PINB;
    mask = 1;
    for(i=0;i<8;i++){
        if((x & mask) == 0)
            return i + 1;
        mask <<= 1;
    }
    return 0;
}


Changed so it uses 0-7 PB instead ot only 0-5..... and then I wiped out the stuff for PINC and PIND

Problem is that PIND keys still work and PB6 and PB7 still don't produce any keypress (PINC dont exist on attiny2313)

I also changed the #define NUM_KEYS 8 /* instead of 17 */


Have some ideas that I need to change something concerning
static const uchar keyReport[NUM_KEYS + 1][2] PROGMEM = {
/* none */ {0, 0}, /* no key pressed */
/* 1 */ {MOD_SHIFT_LEFT, KEY_A},

etc....

But i tried to change all to KEY_Z and I still write A,B,C,D etc so this try didnt help me either.


Some one care to explain a bit and point me into the right direction ?

Saw that a guy on the forum had done a "Hello world" when he pressed the PD0 key but the example code was gone =( maybe that would have helped me to understand.

Appreciate all help and pointers I can get.

Think i got the fuses and hardware all working correctly.... now i only need to understand the C code fully.

////Ricke

[/code]

Posted: Thu Aug 21, 2008 2:44 pm
by Ricke
Looks like my programmer or chip stopped working.

I programmed the Attiny2313 with a blink led demo and i get no error but the HIDKeys program is still in the chip =(

Posted: Thu Aug 21, 2008 3:20 pm
by Ricke
Well I got it to work now... was my own fault.

With the MAKEFILE i had; i could not set the fuses and burn the program at the same time....

I removed the part where it set fuses and then it startet to write program again

///Ricke

Re: HIDKeys converted to Attiny 2313 problems (understand C-code

Posted: Wed Apr 22, 2009 10:09 am
by Goeck
Hey Rickie,

could xou do me a huge favour and paste the whole main.c and the fuse setting here?
I can't get the code running on my ATTiny2313. Something is missing... I don't know what it could be. I changed all he registers for timing etc. but still the Tiny doesn't seem to work.

Thank you!!!

Greeting from Germany
Goeck

Re: HIDKeys converted to Attiny 2313 problems (understand C-code

Posted: Thu Apr 23, 2009 9:31 am
by Goeck
Hey guys,

I am really in need of some help. I want to get this thing rolling by this week. Please someone drop some suggestions here.

Thanks!

Re: HIDKeys converted to Attiny 2313 problems (understand C-code

Posted: Wed May 13, 2009 10:22 am
by mschoeldgen
I'm sorry for the late resonse but i just recently found this wonderful software. I've been experimenting a lot with it and perhaps i'm able to give some hints. I'm compiling and flashing with AVR Studio on XP, btw and use the ISPMkII programmer.
1. Set Device and F_CPU in your makefile . Sounds trivial but is an absolute necessity. In AVR Studio you should enter Device and Frequency in the Options for your project.
2. In case you cannot find a hardware wiring for your CPU from one of the examples , use INT0 for the D+ line and Bit0 of the same port for D- ( gee, i hope i didn't confuse them now :P ) . Using Bit1 on my ATTiny's didn't work at all.
3. If possible run your CPU from a crystal. The internal RC oscillator does work at least on the 25/45/85 but is a bit more unreliable than the crystal. I'd also think that the 2313 again uses a different procedure to calibrate it so the provided examples have to be modified.
4. Provide sufficient power while programming your chip. Most of the Tiny will require at least 3.6 Volt when running at 16-18 Mhz. If you're in for the 12Mhz version this shouldn't be a problem.