Page 1 of 1

How to debug? AVR-USB device does not respond to host

Posted: Mon Dec 15, 2008 7:06 pm
by sivan_toledo
Hi,

I built an AVR-USB device using an ATtiny861 with a 16MHz crystal. The clock source works and I can program the chip using ISP. I programmed to it a project to control an I2C device.

The chip runs at 5V and the D+ D- lines are protected by 3.6V zeners (but 1W zeners, not low-power ones as suggested).

When I plug it in, the Linux host detects it as a low-speed device but fails to communicate with it.

Here is what the kernel on the host says:

usb 1-1.4: new low speed USB device using ehci_hcd and address 22
usb 1-1.4: device descriptor read/64, error -32
usb 1-1.4: device descriptor read/64, error -32
usb 1-1.4: new low speed USB device using ehci_hcd and address 23
usb 1-1.4: device descriptor read/64, error -32
usb 1-1.4: device descriptor read/64, error -32
usb 1-1.4: new low speed USB device using ehci_hcd and address 24
usb 1-1.4: device not accepting address 24, error -32
usb 1-1.4: new low speed USB device using ehci_hcd and address 25
usb 1-1.4: device not accepting address 25, error -32

Any advice on how to debug this? Are the 1w zeners at fault?

What I thought of doing is adding an LED that will tell me how far the code goes, whether it sees the hosts requests, etc. But I'll appreciate any advice.

Thanks, Sivan Toledo

Posted: Mon Dec 15, 2008 9:04 pm
by sivan_toledo
OK, I see from previous posts that 1w zeners won't work.

I switched to 500mW ones (1N5227) and the voltage on D- is till too low, around 2.1v. I changed the 2.2k pullup to 1k, but it only pulls it up to 2.7 or 2.8v, still too low.

Should I just reduce the pullup until I get above 3v?

Thanks, Sivan

Posted: Tue Dec 16, 2008 3:22 am
by Grendel
W/ a tiny461/861 I have sucessfully used the following values:

- 3V6 500mW 1N5227 to ground on D-/D+
- R 68 in series betw. diodes and MCU
- R 2k2 to Vcc on D- (at the USB connector, not after 68 !)

Posted: Tue Dec 16, 2008 5:10 am
by sivan_toledo
Thanks. I can try to move the 2.2k resistor to the D- line (right now it's after the 68 Ohm), but I can't see why that would make a difference; the extra 68 Ohm don't make a real difference for a 2.2k.

Maybe something else is wrong with my board. I'll try to do some more testing tomorrow with just a 2.2k resistor and the zener to see what is going on.

Posted: Wed Dec 17, 2008 2:22 am
by sivan_toledo
I'm still having problems.

I now run the AVR at 3.3V with a regulator, to avoid the zener-diode issues. D- is now at 3V at rest, pulled up by a 1.5k.

But the host still can't communicate with the device. I tried to see what is going on by turning on an LED at critical points in the code, but I am not actually sure where to check. I added a check in usbProcessRx, to see whether the device receives anything, and it does not turn on (see below).

Is there a good way to debug this? Is there an ISR that gets invoked, or a function that is called at SE0 or before/after AVR-USB starts receiving a packet?

Here is where I added the LED turn-on code that is never reached:

static inline void usbProcessRx(uchar *data, uchar len)
{
usbRequest_t *rq = (void *)data;
...
if(usbRxToken == (uchar)USBPID_SETUP){
PORTA &= ~(1<<5); // low is on

Posted: Wed Dec 17, 2008 4:54 pm
by sivan_toledo
OK, I discovered one issue: I was not using the INT0 pin for D+, since I kept the PB0 and PB2 pin assignments when I ported the code from ATtiny45. Now I switched to PB6=INT0 for D+ and PB3 for D-.

But the host still can't communicate with the device.

I used an LED to verify that the code invokes the INT0 ISR. But there, it always jumps to sofError, never to foundK.

Any hints on how to debug from here?

Thanks, Sivan

Posted: Wed Dec 17, 2008 11:07 pm
by sivan_toledo
Success at last. I had D+ and D- connected incorrectly to PB3 and PB6. Now working fine; I'm happy.