AVR-USB Device Not Recognized on Atmega8

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 8:09 pm

See my post above ^^^

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 8:10 pm

The debug output you see shows that you receive USB reset. No USB data packet is received. Have you wired the interrupt correctly?

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 8:15 pm

I have D+ (green wire) wired to PD2 (INT0) on the Atmega8. I believe that is correct.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 8:30 pm

Hmm... Can you verify whether an interrupt occurs at all, e.g. by replacing the interrupt routine with something which prints debug output?

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 8:38 pm

Which function is this and where is it located? Is it timerInterrupt or usbFunctionSetup in main.c or something else?

EDIT: timerInterrupt constantly prints debug output. usbFunctionSetup does nothing.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 8:44 pm

I mean the handler for INT0, this is in the assembler module. Declare your own handler for INT0 and rename the function in usbdrvasm12.inc (or whatever module you use). The name is USB_INTR_VECTOR (a macro defined to the actual name). Temporarily rename it to something else to avoid linker conflicts.

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 8:59 pm

I disabled USB_INTR_VECTOR in usbdrvasm.S and I added this code to main.c

Code: Select all

ISR(INT0_vect) {
 
   DBG1 (0xFF,0XFF,4);

}

Every time I reset I get the output from the message. Assuming I did this correctly it appears that INT0 is working.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 9:16 pm

You can distinguish this log from the USB reset log because it's "ff: xx xx xx xx" (ff with four random bytes). To be sure that it's this log, you can use DBG1(0x50, NULL, 0) instead.

You should see a couple of interrupts after connecting USB. When the host gives up after a few seconds, these interrupts should stop.

Assuming that the interrupt works, the handler does not interpret the data correctly. In this case: Are you sure that you compile for the right clock rate? Are you sure D+ and D- are not swapped?

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 9:37 pm

The interrupt vector I used:

Code: Select all

ISR(INT0_vect) {
   DBG1(0x50, 0, 0);
}


The output I received:

Code: Select all

ff:
ff:
ff:
ff:
ff:
ff:
ff:
ff:
ff:
ff:
ff:
ff:
f50:
f:


The D- and D+ should be correct. D- is connected to PB0 and D+ is connected to PB1 and PD2. All of the configuration is set at 12Mhz and the fuse bytes are programmed as per the makefile:

Code: Select all

# Fuse low byte:
# 0xef = 1 1 1 0   1 1 1 1
#        ^ ^ \+/   \--+--/
#        | |  |       +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
#        | |  +--------------- SUT 1..0 (BOD enabled, fast rising power)
#        | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
#        +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
#
# Fuse high byte:
# 0xdb = 1 1 0 1   1 0 1 1
#        ^ ^ ^ ^   \-+-/ ^
#        | | | |     |   +---- RSTDISBL (disable external reset -> enabled)
#        | | | |     +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
#        | | | +-------------- WDTON (watchdog timer always on -> disable)
#        | | +---------------- SPIEN (enable serial programming -> enabled)
#        | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
#        +-------------------- DWEN (debug wire enable)
#fuse:
#   $(AVRDUDE) -U hfuse:w:0xdb:m -U lfuse:w:0xef:m

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 9:45 pm

Umm... These fuse values are for the ATTiny2313, if you started from PowerSwitch. The ATMega8 needs different values. You are lucky that you did not burn a fuse which makes serial programming impossible.

Please copy the fuse values from a project based on the ATMega8, e.g. RemoteSensor.

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 9:56 pm

I don't know why I did that, but I got the fuses changed. I am lucky that the chip continued to work. I am still getting the same blank output.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 10:04 pm

OK. Then going back to your debug output from above: You see USB RESET (ff:) and one interrupt during reset (50:). You should see many more interrupts, one for each packet sent to the AVR. Since the AVR does not answer, the host should retry the packets several times and retry the entire enumeration procedure several times.

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 10:12 pm

I will try another computer and check the serial output.

kwebdesigns
Rank 1
Rank 1
Posts: 23
Joined: Sat Mar 15, 2008 7:46 pm

Post by kwebdesigns » Tue Mar 18, 2008 10:18 pm

I get the same thing on another computer. One computer has Vista and the other has XP and I also tried it on a hub.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Mar 18, 2008 10:27 pm

Since you don't get any data packets (or only one at most), I suspect an electrical problem. Did you measure voltage levels at D+ and D-? Is it possible that a wire in the cable is broken or that the pull-ups of the AVR are active for the I/O ports? Just guessing...

AVR-USB is proven to work on the ATMega8. This must be a simple issue. However, it's hard to say what it is from remote...

Post Reply