Page 1 of 1

PowerSwitch on atmega16

Posted: Thu May 08, 2008 9:52 pm
by izua
Hi! I'm a new user of avrusb. I've chosen it because it came with a lot of examples, both device side and driver side.
My first question, which I haven't yet been able to figure out, is: PowerSwitch identifies itself as what kind of USB device?

Next, here's my log of trying to set up PowerSwitch on an attiny2313.
Downloaded source files, moved them to C:\ since compiler was complaining. (I'm running AVR Studio in WinXP SP2). Included all files, successfully compiled for attiny2313 at 12 MHz. Started programmer, configured fuses, checked if attiny is bricked. Nope. Breadboarded the schematic: Dropped the regulator, external power supply, added two diodes in series to get the voltage drop, added the 1.5k and 1M resistors, used 50ohm instead of the 68 resistors. Added a single cap of 10uF on the power rails.

The whole thing is now powered via USB, including my programmer (STK200 homemade). Kanda AVRISP (programmer software) sees the device. Burnt the hex into the device, leds light up, "usb device not recognised" pops up, avr is now bricked. Try to unbrick, but nothing works.

I now switched to atmega16.
I changed the following: using PD0 and PD2 for D- and D+ (PD2 has INT0). I also use the whole PORTC for output instead of breaking the incoming data for two ports. Changes:

usbconfig.h

Code: Select all

#define USB_CFG_IOPORTNAME      D
#define USB_CFG_DMINUS_BIT      0
#define USB_CFG_DPLUS_BIT       2


main.cpp

Code: Select all

int main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    odDebugInit();
    DDRD = ~(1 << 2);   /* all outputs except PD2 = INT0 */
    PORTD = 0;
    PORTB = 0;          /* no pullups on USB pins */
/* We fake an USB disconnect by pulling D+ and D- to 0 during reset. This is
 * necessary if we had a watchdog reset or brownout reset to notify the host
 * that it should re-enumerate the device. Otherwise the host's and device's
 * concept of the device-ID would be out of sync.
 */
    //DDRB = ~USBMASK;    /* set all pins as outputs except USB */
   DDRD = ~USBMASK;
    computeOutputStatus();  /* set output status before we do the delay */
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){         /* fake USB disconnect for > 500 ms */
        wdt_reset();
        _delay_ms(2);
    }
    usbDeviceConnect();
... }

static void outputByte(uchar b)
{
    //PORTB = (PORTB & ~0xfc) | (b & 0xfc);
    //PORTD = (PORTD & ~0x30) | ((b << 4) & 0x30);]
   PORTC = b;
}




No AVR ever enumerated. What should I do?

Posted: Fri May 09, 2008 11:04 am
by christian
PowerSwitch is a custom class device. You should get a "new hardware found" dialog on Windows.

Please download the newest version of the driver from http://www.obdev.at/products/avrusb/download.html. It contains some examples which are less complex than PowerSwitch and they should run on almost any AVR with only very little changes.

What you you mean with "the chip is bricked"? Do you mean that it can't be programmed or read? In this case you must have a hardware problem.

reply

Posted: Sat May 10, 2008 5:21 pm
by izua
when you change clock settings for example, and you end up with the chip inaccessible. it's an odd term, but that's how i noticed people refer to this state.

yes, the chip is bricked, and every other chip except that one works. even that one, isolated on the breadboard doesn't work. must be something with clock settings i guess.


I'll try the osc calibration thing from the link supplied. Thanks!

Posted: Sat May 10, 2008 6:16 pm
by christian
Clock settings are done by setting fuse values. And it's impossible to change fuse values from within the firmware. Maybe the chip is blown, not bricked (and not stoned...). I therefore suspect a severe hardware problem.

Oscillator calibration is only required if you run from the RC oscillator, not with an external crystal.