SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By tfuruya
#80121
I am new to AVR microcontroller and I have problem with my first project: blinking an LED.
Problem: I can't get it to blink.

I recently bought ATmega328 with Sparkfun AVR Pocket Programmer and I'm not sure if it is my circuit or programmer or microcontroller that is wrong.
I stronly feel that the programmer is not working properly but I thought that asking here before sending an email to Sparkfun is a good idea.



OS: Microsoft Windows XP Proffesional Version 2002 Service Pack 3
Programmer: Pocket AVR Programmer (usbtiny from Sparkfun)
(installer for it is in the same page as in hyperlink above)
Program used: AVRDude
Microcontroller: ATMEGA328P-PU
File used: blink_1MHz.hex (from Sparkfun Tutorial)
(above zip also contains C code)

Most of the time after connecting the USB, the computer detects unkown hardware although I installed it.
When this happens, only the blue light in the programmer lights up.
I typed the following in command prompt after changing directory to where blink_1MHz.hex is saved:
Code: Select all
avrdude -c usbtiny -B 1 -p atmega328p -U flash:w:blink_1MHz.hex
The result is:
Code: Select all
avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

Once in a while (after disconnecting and re-connecting the usb about 20-30 times), the Stat1-red-light in the programmer lights up.
When this happens, I type the above command again and get the same results.
However, sometimes, the Stat2-red-light blinks once and the result is:
Code: Select all
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
Once in about another 20-30 times of repeating the above when Stat1-red-light is lit, I get the following:
Code: Select all
avrdude: error: usbtiny_transmit: usb_control_msg: sending control message faile
d, win error: A device attached to the system is not functioning.


avrdude: error: usbtiny_receive: usb_control_msg: sending control message failed
, win error: A device attached to the system is not functioning.
 (expected 4, got -5)
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00s
avrdude: error: usbtiny_receive: usb_control_msg: sending control message failed
, win error: A device attached to the system is not functioning.
 (expected 4, got -5)

avrdude: error: usbtiny_receive: usb_control_msg: sending control message failed
, win error: A device attached to the system is not functioning.
 (expected 4, got -5)
Reading | #################                                  | 33% 0.10s
avrdude: error: usbtiny_receive: usb_control_msg: sending control message failed
, win error: A device attached to the system is not functioning.
 (expected 4, got -5)
Reading | ################################################## | 100% 0.14s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude: error: usbtiny_transmit: usb_control_msg: sending control message faile
d, win error: A device attached to the system is not functioning.


avrdude done.  Thank you.

Image 1:
Image
Image 2:
Image
Image 3:
Image
Image 4:
Image
Image 5:
Image
Image 6:
Image
Image 7:
Image

I have checked the circuit several times including making sure that the wires were firmly connected.


Other facts:
I do not have a usb hub as this page suggests to use (and I do not want to buy one since it might still not work).
One of the comments in this page from Sparkfun says that the MISO,SCK,RST,MOSI is printed in reverse but I have tried connecting both ways.


Is it the programmer thats broken?
Is it the microcontroller thats broken?
Is my circuit wrong?
Should I contact Sparkfun?
Did this happen to those using the same Pocket Programmer?


I would appreciate any comments, suggestions, opinions, similar problems, etc.

Thank you!!
User avatar
By leon_heller
#80123
You don't seem to have any decoupling on the AVR. You should have a 100 nF capacitor directly across the Vdd and Vss pins. Solderless breadboards aren't very reliable, I never use them.

Leon
By deadsy
#80134
>Is it the programmer thats broken?
Yes. Search on posts about this programmer.
It doesn't comply with the USB 2.0 spec.

>Is it the microcontroller thats broken?
Maybe.

>Is my circuit wrong?
Maybe.

>Should I contact Sparkfun?
If you like.
You could replace the programmer with one that probably works properly.
http://search.digikey.com/scripts/DkSea ... AVRISP2-ND
Or - you could fix it, as I have done. Do a post search.

>Did this happen to those using the same Pocket Programmer?
Yes.
User avatar
By leon_heller
#80137
Or, buy an Atmel Dragon. It's more expensive but offers in-circuit debugging as well as programming.

Leon
By tfuruya
#80145
Thanks for the replies people!

To leon:
leon_heller wrote:You should have a 100 nF capacitor directly across the Vdd and Vss pins
Is this necessary? Shouldn't it work without them too?
By the way, I have no idea about circuits so I don't know why or what those capacitors do.
(and to be honest, wikipedia just explained decoupling capacitor with words I don't understand - I feel very stupid)
leon_heller wrote:buy an Atmel Dragon
yes, I would definitely buy one if I had enough cash.


To deadsy:
deadsy wrote:You could replace the programmer with one that probably works properly.
Yes, ATAVRISP2 is one of the programmer I was thinking of buying at first.
BUT, this person told me about this Pocket Programmer which turned out to be cheaper.
At the same time, Sparkfun describes it as though it has features comparable to ATAVRISP2-ND.

From your post,
deadsy wrote:With my code size getting bigger now (all of 700 bytes) my chances of a good burn and verify have fallen to around 0.
This is just terrible.

But at least you are using Linux and Sparkfun mentions:
"We've gotten a big response ... from Mac and Linux users having problems"

I am using Windows! It says on the same page:
"We use this programmer extensively on a Windows box and love it"
By deadsy
#80157
This is just terrible.
But at least you are using Linux and Sparkfun mentions:
"We've gotten a big response ... from Mac and Linux users having problems"
I am using Windows! It says on the same page:
"We use this programmer extensively on a Windows box and love it"
Sure - but then you go to the forums where windows users describe the same sort of "can't see the device" problem that Linux and Mac users have.

I think it's possible to get lucky with some USB host controllers being tolerant enough to deal with the out of spec behavior this device has. Other host controllers are more picky and won't deal with it. It's a hardware problem - not a software problem.

It's quite a small problem. With zeners clamping the D+/D- lines the programmer is working well for me. I can program/verify the full 32k without issue- as I understand it the SFE guys will be re-spinning the board with these fixes.
User avatar
By leon_heller
#80170
Even if you don't understand the reason for it, you should always decouple supply pins! Some MCUs simply won't program or work properly if you don't.

Leon
By tfuruya
#80190
From Sparkfun Pocket Programmer page:
egaistek wrote: this programmer does not work under WinXP SP3, Vista and Ubuntu. Under windows no driver wizard pops up, no new devices in device manager. Only power led lights up.
Under Linux the same message "hub 5-0:1.0: unable to enumerate USB device on port 1". Tested on two laptops and desktop pc.
But as a solution,
egaistek wrote: got it working on Linux by connecting it through PCI usb controller based on VIA chip...
tested it on two Vaio laptops (fs415 which old one and fw11er), Ibm laptop (t43 which old one too), on Shuttle XPC (sg31g2), and on intel Mac mini 1.6. All failed.
I have no idea what VIA-chip-PCI-usb-whatever means but it says it doesn't work on Mac and Windows.
And another solution to this was:
tz wrote: Connecting through any hub ... usually works.
Which is a solution I have read in so many posts.

So I will try,
1: connecting through usb hub with external power :(
if above fails,
2: try deadsy way which is tested only on linux
if above fails,
3: try moogle way which works on linux and mac and windows (needs usb-hub for windows) according to him
if above fails,
4: decouple supply pins


I will post my findings.
By theatrus
#80241
Tool problems are the worst. Hopefully collectively we can get you going. :). On another note, you're doing a great job documenting your findings
By tfuruya
#80301
Thanks theatrus. I just felt that it would be nice if this could be used by people other than myself who may be facing a similar problem.

So I got my first project complete!
The LED blinks. I used an usb-hub.


How I managed Pocket AVR Programmer to work on my Windows XP:

--- 1 ---
Connect the programmer to the usb-hub.
I used a cheap one that is not a self-powered hub so it does not take power from an external power supply.
*I borrowed it from a friend who said that if you connect too many things onto it, it wont work. I am guessing that using one with external power is better although it worked for me without it.

--- 2 ---
The computer detected "Pocket AVR Programmer" instead of the usual "unkown hardware"
The stat1-red-light on the programmer also lit.

--- 3 ---
I made target-power switch on the programmer to "Power Target"
I typed in command prompt:
Code: Select all
avrdude -c usbtiny -B 32 -p atmega328p -U flash:w:blink_1MHz.hex
*When this was done with the switch on "No Power," it returned an "initialization failed rc=-1" error.
*The same error was returned when "-B 1" was used instead

--- 4 ---
I made the switch on the programmer to "No Power" and the LED blinked as it should.
*When the switch is on "Power Target," the LED blinked but it did not blink as it was programmed to.



This was the output on command prompt at step 3:
Code: Select all
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "blink_1MHz.hex"
avrdude: input file blink_1MHz.hex auto detected as Intel Hex
avrdude: writing flash (248 bytes):

Writing | ################################################## | 100% 1.49s



avrdude: 248 bytes of flash written
avrdude: verifying flash memory against blink_1MHz.hex:
avrdude: load data flash data from input file blink_1MHz.hex:
avrdude: input file blink_1MHz.hex auto detected as Intel Hex
avrdude: input file blink_1MHz.hex contains 248 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.97s



avrdude: verifying ...
avrdude: 248 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

By DogNo7
#80364
leon_heller wrote:Even if you don't understand the reason for it, you should always decouple supply pins! Some MCUs simply won't program or work properly if you don't.

Leon
I would like to " (ditto) the above comment.

Sometimes an MCU will work without them, sometimes not, it's easier to just buy a gaggle of .1uF tantalums and spread them around your design like candy.

On the 328, it is also a good idea to throw one in betwixt pin 7 and ground. I think it is in the design notes from Atmel.

Also, as you increase the speed of your design, the sources for noise increases, and having the spec'd caps for decoupling is a necessity.

My last remark on this overall topic is that it is easier to read the design notes, and follow specs than it is to (later) figure out which part of the out of spec design is causing problems.

-Kurt
By facklera
#85974
How do you have an image hyperlink without a border? I would like an image on my web page to be a hyperlink, but it automatically puts a border round the image - how can I prevent this? I am using stylesheets.
By desizn104
#93153
ATmega328 with Sparkfun AVR Pocket Programmer taste How are you doing to help explain these little wait.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]