Page 1 of 1

Need help with HID-mouse example

Posted: Thu May 13, 2010 6:33 am
by gator456
I cannot seem to get this most basic example working.

I have implemented the USB using the with-zener.png example. I compiled the example using AVRstudio and AVRISPMkII. I am using an ATmega644 20PU with a 12mhz crystal. THe code compiles just fine and the hex file programs into the AVR. THe checksum comes back clean. When I plug the device into the USB port Windows says that it is an unrecognized device.

I have also written some "flashing LED" programs and they work just fine.

I have also tried the powerswitch example without any luck.

What am I doing wrong.

Re: Need help with HID-mouse example

Posted: Thu May 13, 2010 10:40 pm
by maxi
EDIT:

Sorry, I replied to the wrong post though most of what I mentioned in your other thread applies here too.

Re: Need help with HID-mouse example

Posted: Sat May 15, 2010 5:46 am
by gator456
Maxi

Thanks for responding. I am pulling my hair out trying to get this to work. I was a bit scatterbrained when I did the post and I now see that I left out all the details

I am using a ATmega644 20PU
Programmer AVRisp MKII
I am implementing the hid-mouse example
My circuit is as shown in the with-series-diodes.png from the circuits directory (except mine is a atmega644)
The AVR is driven by a 12mhz crystal
My code is exactly as in the hid-mouse example except:
#define USB_CFG_CLOCK_KHZ 12000 // In usbconfig.h
#define F_CPU 12000000 // first line in main.c
My fuse settings are:
Extended 0xFF
High 0xD9
Low 0xEE
These equate to: brown-out off, SPIEN=on, ext crystal 8mhz startup 1k CK + 0ms, boot flash=4096 words , addr $7000 and everything else off

Re: Need help with HID-mouse example

Posted: Sat May 15, 2010 3:39 pm
by maxi
gator456 wrote:My circuit is as shown in the with-series-diodes.png from the circuits directory (except mine is a atmega644)
The AVR is driven by a 12mhz crystal

According to the datasheet ATmega644 is not rated for 12Mhz operation at < 4.5V. Series diodes will drop the voltage to around 3.5V
Speed Grades
– ATmega644V: 0 - 4MHz @ 1.8 - 5.5V, 0 - 10MHz @ 2.7 - 5.5V
– ATmega644: 0 - 10MHz @ 2.7 - 5.5V, 0 - 20MHz @ 4.5 - 5.5V

Re: Need help with HID-mouse example

Posted: Sat May 15, 2010 9:15 pm
by gator456
maxi

This is good advice. I have the zener diodes. I have tried getting a USB interface working multiple times using the zener diode circuit. I can switch back. I am using a pair of NTE134A Zener's. Are there any special requirements for the zeners?

I have a sampling HP o-scope/logic analyzer coming from a friend on Sunday. Maybe that will give me insight....

Thanks

Re: Need help with HID-mouse example

Posted: Sun May 16, 2010 4:12 am
by maxi
gator456 wrote:Are there any special requirements for the zeners?

None that I could say, other than those recommeded in the wiki. I am using BZXC3V6 myself but you might find it will work without any level conversion, it really just depends on your system. Give it another go with the zeners, see what voltages you read on D+/- Also see what happens using only the 68R resistors.

Re: Need help with HID-mouse example

Posted: Tue May 18, 2010 6:28 am
by gator456
I think I know what is going on, I just dont know how to fix it...

I borrowed a logic analyzer from a friend and I downloaded USBlyzer. THe USBlyzer says that the "Enumeration of device failed". When I look at power up sequence on the D+/D- lines on the logic analyzer I see 6 frames of data. Then I disconnected the D+/D- lines from the AVR and reran the powerup sequence. I saw the same data. If i zoom in on one of the frames I see 1010101110010011010011101110100100... on the D+ line

It seems like to me that the AVR is not responding to the interrupt that is coming in on the D+/D- line. I have them signals connected to PIND2 (D+) and PIND4(D-)

#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 4
#define USB_CFG_DPLUS_BIT 2

Tomorrow or Wednesday I will see if I can write a small bit of code that will flash some LEDs when INT0 is asserted (just to make sure the interrup is working)

BTW I know that the main loop is running because it is flashing a pair or LED's:

Any suggestions?

int main(void)
{
uchar i;
uint8_t toggle = 0;
DDRC = 0xFF;
PORTC = 0x00;
wdt_enable(WDTO_1S);
usbInit();
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
i = 0;
while(--i){ /* fake USB disconnect for > 250 ms */
wdt_reset();
_delay_ms(1);
}
usbDeviceConnect();
sei();
for(;;){ /* main event loop */
wdt_reset();
usbPoll();
if (toggle == 0 ) {
PORTC = 0xFF;
toggle = 1;
// _delay_ms(50);
} else {
PORTC = 0x00;
toggle = 0;
//_delay_ms(50);
}
if(usbInterruptIsReady()){

advanceCircleByFixedAngle();
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
}
}
return 0;
}

Re: Need help with HID-mouse example

Posted: Wed May 19, 2010 6:55 am
by gator456
I examined the VUSB driver and verified the registers it is setting for the interrupts. THen I ran a AVR Studio simulation and verified the correct initialization of EIMSK and EICRA. I also wrote a small program to turn on a LED when INT0 was applied. THe program worked, so I know the INT0 logic is working.

Any suggestions?