Trouble Programming Atmega8 with USBasp

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Currently I am trying to upload the Arduino boot loader, as well as a sketch to an Atmega8 that currently resides on a breadboard.

I have swapped the Atmega8 out with a 328p which gives me no issues, and I've also tried programming an Attiny85 with no issues either.

 

I would just say F it and just use the 328p, but I have a ton of Atmega8's, and I don't want them to go to waste.

 

Here is the error I'm getting.

 

avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

It may also be worth mentioning that I'm using VisualMicro, as well as the Arduino IDE to upload the bootloader/sketch, and not avrdude in command prompt.

 

Any help would be greatly appreciated.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the AVRdude command line?

And what is the complete text AVRdude spits out?

 

If those M8's are new then they probably run on the internal oscillator with F_CPU/8 which means an effective 1MHz clock rate.

This is too fast, and you need to slow avrdude down untill the fuses are set to a more sensible combination.

This is dowe with the -B switch of avrdude. Read it's manual and/or check if this is your issue.

 

Another issue might be that the AVR does not have a clock at all.

I do not know the history of your M8's.

 

Breadboards are also unreliable. The're ease to use and can be very usefull, but they also have quite some limitations.

I've had loads of trouble with a M8 on a breadboard where RxD or TxD was next to the sensitive crystal pins and this was the cause of random glitches.

That took me quite a while to diagnose and my final solution was to simply not use crystals on breadboards, but use an adapter PCB such as arduino nano, and put that in a breadboard.

 

A picture of your breadboard might clarify some things

Have you connected both Vcc and AVcc? GND and AGND?

Do you have some decoupling caps on your breadboard?

(I tend to solder decoupling caps directly on top of the AVR's I intend to use on Breadboards).

 

Long wiring or worn out connectors are other common causes of trouble.

Also wires in which the copper conductor has broken, but not the plastic shield are quite common.

Wires tend to break jus next to solder joints or places that get bent a lot.

You can diagnose this by gently pulling on the wire. The plastic stretches, the copper does not.

 

USBasp is perfectly capable of programming M8's. I still use them myself.

 

Why does your error message start with "avrdude" when you claim you do not use avrdude?

Are your tools some gui front end for AVRdude?

 

 

 

 

 

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I wrote this huge reply over the course of a couple hours while tinkering with it all, and I had eventually managed to figure it all out, but I'll leave the reply anyways.

Turns out all I had to do was upload it with the console, instead of the Visual Micro's "Build and Upload" button. (For those who don't know VisualMicro is a plugin for Visual Studio, it's basically the Arduino IDE with debugging and intellisense)

I'm not sure what avrdude command that Visual Micro sends, but I used  avrdude -c usbasp -p m8 -u -U flash:w:NES_HyperTapper.ino.hex and it uploaded first try without issue.

It is still a little weird why it wouldn't work before, something to do with the fuses though, and it would still be nice to figure out why. If you look in the txt's I attached you will see that each fuse was read as "CA."

In the end I'm happy that it did happen, I've been wanting to learn how to use avrdude from the console, but I kept putting it off. Next step is Atmel Studio.

 

And just in case you don't read to the end, Thanks a lot for the help Paul.

 

 

Paulvdh wrote:

What is the AVRdude command line?

And what is the complete text AVRdude spits out?

 

I'm not sure exactly, I just hit the "Build and Upload" button in Visual Studio and it communicates with AVRdude for me. (

 

Here is what it spits out though.

Please note that I can take out the M8 and pop in a 328 and it uploads just fine.

Uploading 'NES Hypertapper' to 'Arduino NG or older w/ ATmega8' using 'USBasp'
The uploader returned an error
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

 

Edit: While writing this reply, I found out about the "Verbose" button in Visual Micro, which shows everything. I attached it as a txt, its pretty big.

I've been playing around in the console, and I noticed Verbose is a parameter as well.

From what I can tell it should be showing more even with the button unchecked, I guess its all or nothing.

 

Paulvdh wrote:

If those M8's are new then they probably run on the internal oscillator with F_CPU/8 which means an effective 1MHz clock rate.

This is too fast, and you need to slow avrdude down untill the fuses are set to a more sensible combination.

This is dowe with the -B switch of avrdude. Read it's manual and/or check if this is your issue.

 

Another issue might be that the AVR does not have a clock at all.

I do not know the history of your M8's.

 

Yes they are brand new. Apparently there is a jumper on the USBasp (JP3 I believe), which will slow it down to 1MHZ. I tried jumping it with no luck though.

I think its time to learn how to use AVRdude in a console, cause I have no options like that with the IDE.

 

Paulvdh wrote:

Breadboards are also unreliable. The're ease to use and can be very usefull, but they also have quite some limitations.

I've had loads of trouble with a M8 on a breadboard where RxD or TxD was next to the sensitive crystal pins and this was the cause of random glitches.

That took me quite a while to diagnose and my final solution was to simply not use crystals on breadboards, but use an adapter PCB such as arduino nano, and put that in a breadboard.

 

A picture of your breadboard might clarify some things

Have you connected both Vcc and AVcc? GND and AGND?

Do you have some decoupling caps on your breadboard?

(I tend to solder decoupling caps directly on top of the AVR's I intend to use on Breadboards).

 

Long wiring or worn out connectors are other common causes of trouble.

Also wires in which the copper conductor has broken, but not the plastic shield are quite common.

Wires tend to break jus next to solder joints or places that get bent a lot.

You can diagnose this by gently pulling on the wire. The plastic stretches, the copper does not.

 

The breadboard is only temporary, right now I'm just trying to make a rough draft of my circuit, and then I'm going to etch the board after I build a schematic.

Eventually I'll to make my own USBasp with sockets, maybe next week.

 

I only have the 6 pins hooked up, and then a crystal and its 2 caps.

VCC, GND, RST, SCK, MISO, MOSI.

 

And I know you've probably already read it, but it is working with the 328.

 

No Decoupling caps.

 

Here is my embarrassing setup. The smaller bread boards are what I'm using to program it, ignore the Attiny and piezo buzzer, I've just been too lazy to put them away.

I would use a bigger breadboard, but I don't want to rip apart some old circuits at the moment.

I included an image of my circuit too(the 2 big boards), as I was trying to program right from that, but I couldn't get it to work at all (the 328).

So that's when I just jimmied up the 2 small boards.

You can probably see that my circuit is only half done, if I decide to keep a breadboard version, I'll make the rest of the wires low profile like the others.


 

Paulvdh wrote:

USBasp is perfectly capable of programming M8's. I still use them myself.

 

Why does your error message start with "avrdude" when you claim you do not use avrdude?

Are your tools some gui front end for AVRdude?

 

 

You probably have guessed it, but the arduino IDE and visual micro, use AVRdude behind the scenes.

 

 

Thanks for the reply Paul, I really appreciate it.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First:

No reason to be emabarrased about your breadboard setup.

I acutally quite like it.

Some peopble painstakingly straigthen all wires so they run exactly of as many holes as possible which then become inacessable because they think it looks "neat".

Electrons don't care about "neat" and I don't either. I care about easy, practical & fast. Those are the strengths of breadboards.

Using solid wires for the "do once" connections, and then flexible wires for stuff added later keeps the wiring mess on a breadboard down to an acceptable level.

I do it the same way myself.

I've had some trouble with buttons on breadboards though. Because they move when you push them, they genarate much more noise and are significantly harder to debounce when used on a breadboard.

 

About the programmer setup:

If you use Female to Male "Dupont wires" instead of the flat cable then you can put the wires direclty into the green breadboard, and don't need the black breadboard.

I see no connections to AGND and AVCC. these should ALWAYS be connected to GND and VCC.

And also always put a decoupling cap near the power pins of your AVR.

You can not expect any digital electronics to work reliable without decoupling capacitors. It is as simple as that.

 

This message is common with USBasp's with chinese firmware. Chinese firmware does some auto speed schecking and does not understand avrdude's command to set the clock frequency.

The message can be pretty safely ignored, although reading it a gazillion times turned me crasy and that is the main reason I always re-flash my USBasp's with the original Fischl Firmware.

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

 

Apparently there is a jumper on the USBasp (JP3 I believe), which will slow it down to 1MHZ. I tried jumping it with no luck though.

This was an old feature. Later versions support setteng the ISP frequency with software (with "-B" option in avrdude). The Chinese have another firmware variant, which does some auto checking, and probably ignores both "-B" and the jumper, which is just an input pin to the AVR. (USBasp schematic and source code on Fisch's site, together with a bunch of home built USBasp's).

This was my first, I added a power switch and a fuse:

http://www.hoevendesign.com/#ProgrammerUsbAsp

 

AVRdude can be made more verbose with adding more v's. I thik upto 4 give more (but increasinly less usefull) info. Just try -vvvv for fun :)

 

LittleRain wrote:
I'm not sure exactly, I just hit the "Build and Upload" button in Visual Studio and it communicates with AVRdude for me. (

Your spitout_bootloader.txt has a line of text which looks suspicously like an avrdude command line and is very likely the exact command send by your programmer GUI:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega8 -cusbasp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w::m -Uhfuse:w:0xca:m -Ulfuse:w:0xdf:m

 

Both High and  Low fuses with the same value "0xCA" seems suspicous, but I have not looked in the datasheet for a sensible combination of fuses. Your bootloader also attempts to program the fuses:

 -Uhfuse:w:0xca:m -Ulfuse:w:0xdf:m

Fuse settings always confuse me. Atmel made some weird combinations there.

For Fuse settings I sometimes use the online "engbedded" (with an "n") fuse calculator:

http://www.engbedded.com/fusecalc

If i'm in the mood or want to use an unfamiliar chip then I check those values with the datasheet by hand. But I find the fuse settings quite a mess acutally. Meaning of some of the fuses change depending of the value of other fuses.

Fuses are grouped in function, but spread out over the fuse bytes. Fuse functions are also described in different parts of the datasheets.

Like I said before, quite a mess.

I actually much prefer the way it is done in STM32. (With which I have limited experience).

It always starts with a slow RC clock oscillator, and all the things which are "fuses" in AVR is done in software by calling some library routines.

This way they are an integral and unforgettable part of each project you do. All the settings are in the source code files and there is no way to forget them if you archive your project or post it on the 'net / github or mail it to someone.

 

On my (pretty old and unmaintained) web site I posted some pictures of the breadboard adapters I made.

The square pins fit snugly in a breadboard and makes the whole breadboarding experience a lot more reliable.

http://www.hoevendesign.com/jpg/Easy_Breadboarding_Big.jpg

 

I'm happy I have helped in getting it to work. for you.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Thu. Dec 6, 2018 - 03:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Visual Micro worked for about a year when Atmel didn't have "Arduino import" but it was a nasty, insidious piece of adware. Thankfully these days there's no reason you should need it as long as you use Studio 7 for the import feature. For programming just setup avrdude as an external command as shown in 1,000+ internet articles.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:

First:

No reason to be emabarrased about your breadboard setup.

I acutally quite like it.

Some peopble painstakingly straigthen all wires so they run exactly of as many holes as possible which then become inacessable because they think it looks "neat".

Electrons don't care about "neat" and I don't either. I care about easy, practical & fast. Those are the strengths of breadboards.

Using solid wires for the "do once" connections, and then flexible wires for stuff added later keeps the wiring mess on a breadboard down to an acceptable level.

I do it the same way myself.

I've had some trouble with buttons on breadboards though. Because they move when you push them, they genarate much more noise and are significantly harder to debounce when used on a breadboard.

 

Thanks man. And yeah, that is exactly what I was going for, the solid "do once" and then leaving some flexible jumpers.

If I take the top board off the circuit actually works, and the top mess is just optional functionality.

I planned to keep the main bottom board just for kicks, and then I'm just using the top to prototype a board, which I'm currently designing in eagle.

My buttons are also giving me trouble, they seem to work great for a while, and eventually they start popping out. Same is going for the M8, every time I take it out to program it, it just doesn't want to sit right the next time.

 

Paulvdh wrote:

About the programmer setup:

If you use Female to Male "Dupont wires" instead of the flat cable then you can put the wires direclty into the green breadboard, and don't need the black breadboard.

I see no connections to AGND and AVCC. these should ALWAYS be connected to GND and VCC.

And also always put a decoupling cap near the power pins of your AVR.

You can not expect any digital electronics to work reliable without decoupling capacitors. It is as simple as that.

 

Yeah that's a good idea, I literally just used what I had on my table at the time.

Until I make my own programmer with a socket, that should future proof it for the mean time.

 

Paulvdh wrote:

This message is common with USBasp's with chinese firmware. Chinese firmware does some auto speed schecking and does not understand avrdude's command to set the clock frequency.

The message can be pretty safely ignored, although reading it a gazillion times turned me crasy and that is the main reason I always re-flash my USBasp's with the original Fischl Firmware.

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

 

Apparently there is a jumper on the USBasp (JP3 I believe), which will slow it down to 1MHZ. I tried jumping it with no luck though.

This was an old feature. Later versions support setteng the ISP frequency with software (with "-B" option in avrdude). The Chinese have another firmware variant, which does some auto checking, and probably ignores both "-B" and the jumper, which is just an input pin to the AVR. (USBasp schematic and source code on Fisch's site, together with a bunch of home built USBasp's).

This was my first, I added a power switch and a fuse:

http://www.hoevendesign.com/#ProgrammerUsbAsp

 

AVRdude can be made more verbose with adding more v's. I thik upto 4 give more (but increasinly less usefull) info. Just try -vvvv for fun :)

Yeah I was thinking about updating it, but I was reading this one post where a guy then unable to read the fuses, so I didn't know if it would be worth the trouble.

 

Ahh that makes total sense, cause I've never seem any difference while jumping it, and had always wondered why.

 

While researching my issue I had actually found Fisch's site, and that's when I decided I should probably make one with a socket. Pretty much exactly like the one you got there.

You got a pretty neat site there, I like the Atmel Chip Horizontal line splitters, very nice touch.

 

 

 

 

Paulvdh wrote:

LittleRain wrote:

I'm not sure exactly, I just hit the "Build and Upload" button in Visual Studio and it communicates with AVRdude for me. (

 

Your spitout_bootloader.txt has a line of text which looks suspicously like an avrdude command line and is very likely the exact command send by your programmer GUI:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega8 -cusbasp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w::m -Uhfuse:w:0xca:m -Ulfuse:w:0xdf:m

 

Both High and  Low fuses with the same value "0xCA" seems suspicous, but I have not looked in the datasheet for a sensible combination of fuses. Your bootloader also attempts to program the fuses:

 -Uhfuse:w:0xca:m -Ulfuse:w:0xdf:m

Fuse settings always confuse me. Atmel made some weird combinations there.

For Fuse settings I sometimes use the online "engbedded" (with an "n") fuse calculator:

http://www.engbedded.com/fusecalc

If i'm in the mood or want to use an unfamiliar chip then I check those values with the datasheet by hand. But I find the fuse settings quite a mess acutally. Meaning of some of the fuses change depending of the value of other fuses.

Fuses are grouped in function, but spread out over the fuse bytes. Fuse functions are also described in different parts of the datasheets.

Like I said before, quite a mess.

I actually much prefer the way it is done in STM32. (With which I have limited experience).

It always starts with a slow RC clock oscillator, and all the things which are "fuses" in AVR is done in software by calling some library routines.

This way they are an integral and unforgettable part of each project you do. All the settings are in the source code files and there is no way to forget them if you archive your project or post it on the 'net / github or mail it to someone.

 

Ohhh, you're right. I looked for the command but it totally passed by me. It must have been the directory before it.

That is kind of odd that it programs the fuses at the same time, not sure if I like that.

In the end I decided to ditch the boot loader and just upload the sketch, I won't be hooking it up to USB so I didn't see a point.

 

That calculator is exactly what I needed. I've just been googling stuff like "avrdude How to set fuse for internal oscillator" and copying what ever I find. 

 

I myself have never used any micro controllers other than the AVR chips, but I just got some STM32's in the mail a few days ago, blank chips and some blue pills. Thought it would be a good learning experience to compare them, I guess I will see what you mean with the fuses.

 

Paulvdh wrote:

On my (pretty old and unmaintained) web site I posted some pictures of the breadboard adapters I made.

The square pins fit snugly in a breadboard and makes the whole breadboarding experience a lot more reliable.

http://www.hoevendesign.com/jpg/Easy_Breadboarding_Big.jpg

 

I'm happy I have helped in getting it to work. for you.

 

Haha that breadboard has seeing its fair share of projects.

I was browsing your site for a bit there. You got some pretty cool projects.

 

Yeah thanks a lot man, I'm glad I switched from the IDE.

 

 

 

clawson wrote:
Visual Micro worked for about a year when Atmel didn't have "Arduino import" but it was a nasty, insidious piece of adware. Thankfully these days there's no reason you should need it as long as you use Studio 7 for the import feature. For programming just setup avrdude as an external command as shown in 1,000+ internet articles.

 

Oh was it? I guess I paid for the license so I had no ads for me. Although when I had bought it, I had no idea Atmel Studio existed.

I do quite like it though, I even have the plugin for Atmel Studio.. Guess that is kind of redundant, especially cause I don't use it.