ATTiny84-based device (5-volt power) will not enumerate

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Recursive
Posts: 4
Joined: Sun Aug 08, 2010 11:43 pm

ATTiny84-based device (5-volt power) will not enumerate

Post by Recursive » Mon Aug 09, 2010 12:04 am

Hello. I am having trouble getting my V-USB device to enumerate. I think that part of the problem is that I am using the 5-volt power supply that the USB hub outputs, but the wiring instructions for a 5-volt device are not very clear (at least as I understand them). First, it says that "D- requires a pull-up of 1.5k to +3.5V (and the device must be powered at 3.5V) to identify as low-speed USB device." What should I do given that I am using a 5V supply? Also, it says that " A pull-down or pull-up of 1M SHOULD be connected from D+ to +3.5V...If you use Zener diodes...you MUST use a pull-down resistor, not a pull-up." This part is self-contradictory, but it seems to say that I should use a 1 megohm resistor to pull D+ to ground; is this correct?

n-regen
Posts: 5
Joined: Tue Aug 10, 2010 9:51 pm

Re: ATTiny84-based device (5-volt power) will not enumerate

Post by n-regen » Fri Aug 13, 2010 4:49 pm

In most cases, it should be sufficient to connect
  • D- with +5V over a 2,2kOhm resistor
  • D- with the I/O-Pin you chose in usbconfig.h over a 470 Ohm resistor
  • D+ with INT0 and the I/O-Pin you chose in usbconfig.h (usually INT0) over a 470 Ohm resistor
(According to the USB-specification, the voltage-levels of D+ and D- should be between 0V and 3,5V, which is why all V-USB-examples use some way (diodes, voltage regulators, etc.) to clip the supply voltage or data-lines to 3,5V. However, in most cases, it will be sufficient to power the AVR with 5V and use a 470 Ohm series resistor on the data lines, as i wrote above.)

Concerning the 1M resistor, the Readme.txt in the current v-usb-package sais the following:
Most examples have a 1M pull-down resistor at D+. This pull-up ensures that
in self-powered designs no interrupts occur while USB is not connected. You
may omit this resistor in bus-powered designs. Older examples had a pull-up
resistor instead. This is not compatible with the zener diode approach to
level conversion: 1M pull-up in conjunction with a 3.6 V zener diode give an
invalid logic level.


By the way, the pull-up from D- to +3,5V or +5V tells the computer that your device is a low-speed one. If you were building a high-speed device (which isn't possibly using an AVR), you would have to pull D+ to +3,5V or +5V.

Recursive
Posts: 4
Joined: Sun Aug 08, 2010 11:43 pm

Re: ATTiny84-based device (5-volt power) will not enumerate

Post by Recursive » Sat Sep 04, 2010 4:37 am

That didn't work. I still cannot get any VUSB-based device to enumerate. To simplify the problem, I tried to get PowerSwitch rather than VUSB proper to work, editing usbconfig.h and main.c and then flashing the device. My modifications to usbdrv.h follow; note that I had D- wired to PB1 in series with a 470 ohm resistor and pulled up to +5V with a 2200 ohm resistor; D+ was wired to PB2 (which is also INT0) over another 470 ohm resistor.

Code: Select all

#define USB_CFG_IOPORTNAME B
#define USB_CFG_DMINUS_BIT 1
#define USB_CFG_DPLUS_BIT 2

I'm using a 12 MHz oscillator (not a crystal but a self-contained unit), so I didn't set a CPU frequency. I also left all other settings as their defaults. My modifications to main.c were as follows:

Code: Select all

static void outputByte(uchar b)
{
    PORTA = b;
}
...
int main(void)
{
...
    DDRA = ~0;
    DDRB = 0;
    PORTB = 0;
...
}

The only thing I can think of at this point is that there is device-specific code embedded in PowerSwitch somewhere that I can't find that is preventing the ATTiny84 from being compatible. When I power the device,
all the outputs (i.e. all the pins on the A port) are set according to the first byte of eeprom, as they should be, PB2 (D+) reads at 0 volts, and PB1 (D-) reads at 3.46 V. I can't figure it out; can anyone help?

n-regen
Posts: 5
Joined: Tue Aug 10, 2010 9:51 pm

Re: ATTiny84-based device (5-volt power) will not enumerate

Post by n-regen » Sat Sep 04, 2010 4:30 pm

Recursive wrote:I'm using a 12 MHz oscillator (not a crystal but a self-contained unit), so I didn't set a CPU frequency.

You do need to set the correct CPU-frequency, no matter from where you get your clock, so the V-USB-code can select the assembler-code matching your frequency. You also must set the clock-fuses to "Ext. Clock", so the µC uses the external oscillator as its clock source. By the way, did you disable the CKDIV8-fuse? If you didn't, the µC will run on a 1,5MHz clock when supplied with a 12MHz clock, as this fuse makes it divide the clock by 8 internally.
If I'm not mistaking, you should set the high fuse to 0xDF, the low fuse to 0xE0 and the extended fuse to 0xFF (assuming that you don't use the brownout detection etc.). You should however check these values using the AVR Fuse Calculator before setting the fuses, so I'm not responsible in the unlikely case that they will render your µC unusable. :wink:

Code: Select all

    DDRA = ~0;
    DDRB = 0;
    PORTB = 0;

Your notation is a bit awkward (though not faulty). Usually, these values are written as 0xFF and 0x00.
Furthermore, DDRx and PORTx default to 0x00, so you don't need to explicitly set them to this value.

Recursive
Posts: 4
Joined: Sun Aug 08, 2010 11:43 pm

Re: ATTiny84-based device (5-volt power) will not enumerate

Post by Recursive » Sat Sep 04, 2010 10:45 pm

I explicitly set the CPU frequency (I'm confused as to why this is necessary, since the code says "Default if not specified: 12 MHz"):

Code: Select all

#define USB_CFG_CLOCK_KHZ 12000

I also flashed the fuses according to the ATTiny2313 example in the makefile (a perusal of the ATTiny84 manual shows that its fuses are identical, so using the same same setting as I did should be appropriate). That is, hfuse:0xdb, lfuse:0xef . I already had them set almost to these values (I didn't have brownout detection enabled before). Still no luck.

Recursive
Posts: 4
Joined: Sun Aug 08, 2010 11:43 pm

Re: ATTiny84-based device (5-volt power) will not enumerate

Post by Recursive » Sun Sep 05, 2010 12:14 am

I noticed that, when the device is connected to my ThinkPad, the lsusb command takes on average 2.5 seconds before producing its output (which does not show any indication that the device is connected). When the device is disconnected, it takes only 0.1 second for the command to return. Similar results occur on my eeePC. Obviously, something is happening, but it still isn't working. I've tried changing the ATTiny84 for another identical part, doing the same for the oscillator, and checked connectivity several times: all is as it should be. Any ideas? Could it be the fact that I'm using PowerSwitch, which uses an old version of VUSB, as far as I can tell?

Post Reply