Device Signature problem in connection
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Device Signature problem in connection

by rainnyday on Sun Aug 19, 2012 11:33 am

I'm using USBtiny kit to program the Atmega 328P chip on development board. I'm having an issue on AVR step: "the Device Signature is different with Expected Signature", please help.

Window 7 64 bits. AVRdude 5.10.0
Atmega 328P chip comes with blank, i'm not sure that i have to download the AVR bootloader first in order to be regnornized by the USBtiny
Or could be wiring problem?


screen shot.jpg
screen shot
screen shot.jpg (37.15 KiB) Viewed 2218 times
08192012219.JPG (866.14 KiB) Viewed 2218 times
dev. board
dev.board.jpg (215.83 KiB) Viewed 2218 times
Posts: 3
Joined: Sun Aug 19, 2012 10:48 am

Re: Device Signature problem in connection

by Wody on Sun Aug 19, 2012 12:29 pm

You are programming an Atmega328p, but in the avrdude-commandline, you specify a different chip, the Atmega8.
Change the commandline to actually program the Atmega328, by using the right partnumber.
avrdude -c usbtiny -p m328p

Of course that just makes a connection, you'd still need to specify what you want to burn on the m328p
If you need help with that, don't be afraid to post!
Posts: 66
Joined: Thu Jul 12, 2012 5:19 pm

Re: Device Signature problem in connection

by rainnyday on Sun Aug 19, 2012 12:59 pm

Awesome ! it works now. Thanks Wody. I could send the test_leds.hex over and did blink the led.

Do you know the command for the same Atmega 328P chip but has arduino bootloader on it? I just want to see if it recognizes the chip on this dev. board ?
I tried the below command but didn't work

avrdude -c usbtiny -p m328p

Thanks for your advice
Posts: 3
Joined: Sun Aug 19, 2012 10:48 am

Re: Device Signature problem in connection

by Wody on Sun Aug 19, 2012 3:21 pm

Normally, when you program the atmega on the arduino, it uses the usb-serial-chip (the ftdi or the seperate atmega chip on the arduino) as a connection, and the bootloader, as the programmer.

In your case, you want to talk with the chip, but leave the bootloader intact, so you can use it again in an arduino. Since you specified the right programmer, and you could upload the test_leds.hex, you know the usbtiny is working, and so that commandline should be working, because it worked on the chip you uploaded the test_leds.hex to.

So, that means we have to find out what is different, and so the question is, how did you set up your breadboard, most importantly, are you using a 16mhz crystal? I ask because I don't have crystals, but do have some 328p and 1284p, and the factory-fresh 328p I couldn't upload anything to, but I could upload to the 1284p, because apparently it was using the internal oscillator.
Since you take the 328p from the arduino, which has a crystal, you would need to use one on your breadboard too.

If you aren't using a crystal, but do have an arduino, you can use that to generate a 8Mhz signal, and that can act as an oscillator for the 328p on the breadboard. That isn't good for running stuff because the timing will be wrong, but it will be enough to make it talk to a programmer.

Anyway, to upload a sketch with avrdude to a 328p where you want to keep the boatloader, you have to do two things differently than normal. First, you have to make sure your sketches are small enough so they don't upload the bootloader (so 30,smaller than 720 bytes), and second, use the -D flag with avrdude, so it doesn't empty the flash.

Another way to burn sketches, to your 328p on the breadboard, is to use the arduino IDE. You can hold down shift or ctrl and then hold your mouse over upload (with the arrow), instead of 'upload' it will then say 'upload using programmer'. and then click. It will start up avrdude the same as you manually would do, except with that -D flag, so there isn't anything to make it magically talk to the 328p on the breadboard if avrdude already doesn't.

Suppose you erase the bootloader, because you forgot -D for example, or made a program too big, I suppose there is a commandline for burning the bootloader as well, but I didn't do that so right now I am not sure what that is :) But with the IDE, you can select the board the 328p came from, and select usbtinyisp as programmer, and then select 'burn bootloader' from the same menu.

Anyway, we first have to figure out why it won't talk with avrdude, so if it is the crystal-thing, then we know and can find a solution, if not, make sure you put it in the same position as the other one, that did work.

If this doesn't help, it would be good if you could post your breadboard-layout, or which one you are using.
Posts: 66
Joined: Thu Jul 12, 2012 5:19 pm

Re: Device Signature problem in connection

by rainnyday on Sun Aug 19, 2012 6:53 pm

Thanks for pointing out directions to go. i'll start working on it
God bless !
Posts: 3
Joined: Sun Aug 19, 2012 10:48 am

Re: Device Signature problem in connection

by Wody on Mon Aug 20, 2012 1:09 am


I am glad you liked my answer, but to be honest, I didn't, because I was sort of guessing at some things. Not that they were really wrong or anything like that, but I just didn't know exactly what was going on.
So, I couldn't sleep (because it is 30c inside even though it is 20c outside), I figured I'd set up an atmega328p on a breadboard, and see if I could provide better instructions.

I will tell you some of what I did, so you can recreate it, and experiment.
But, the big conclusion, which is very important, and why things do not work as you'd expect, is the following:

If you put an atmega on a breadboard, and provide power to it, so you can program its flash, it will be running whatever is loaded inside it, and that can give errors and problems flashing.

What does that mean? Well, when the chip gets power, it starts running whatever it is on the flash. So, if you then tell it to program itsself, it will do that, but at the same time, keep interacting with the flash to keep running whatever it is running, so it doesn't write things properly, and corrupt the flash-area.

The good thing is, you can tell avrdude to erase the chip, which will stop it running, and then you can upload new content. So 'corrupt the flash-area' sounds scary and dangerous, but it's not that bad fortunatly.

Lucky for us, there is an exception. If you flash the bootloader to the chip, it will not run the 'sketch' area, because that will be empty, and you can upload stuff and keep the bootloader intact, and it will verify and work correctly.
Of course, after uploading, the chip will reset, the bootloader starts, which sees there is content, and start running that program, so it only works on a chip that only has the bootloader.

First, I don't have an usbtinyisp (yet), so as programmer, I used an arduino, with the ArduinoISP sketch on it.
I know you do have an usbtinyisp, but I'll still write it like I did, so you can follow along and should get the same results. After that, I'll write how to make it work for usbtinyisp.

I also don't have any crystals, so I changed arduinoIsp a little, to generate an 8Mhz signal, which I use to get the chip on the breadboard going. (I didn't know how to do that myself though. But somebody did!)

Unfortunatly, the pin that is used for that (because it is connected to the timer) is already in use by arduinoisp for an led, so I also had to change that.
So, instead of
#define LED_HB 9
I made it:
#define LED_HB 6
( I also don't have any LEDs connected, but better safe than sorry )

In the setup function, below the led-stuff, so near the end of that, I put the following:
Code: Select all | TOGGLE FULL SIZE
 // set up 8 MHz timer on pin 9
  // Code from Atmega Board Programmer by Nick Gammon
  // at http://www.gammon.com.au/forum/?id=11635&page=999
  // Also info at http://www.gammon.com.au/forum/?id=11643
  pinMode (9, OUTPUT);
  // set up Timer 1
  TCCR1A = _BV (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle

After I had that running, I went to build the breadboard. Generally, I used the bare breadboard-layout for uploading the bootloader that is at http://arduino.cc/en/Tutorial/ArduinoToBreadboard

It provides a good overview, but the pictures are a bit small, so, I load up my changed arduinoIsp sketch in the arduino-ide, with the list of names, and the pins they have to be connected to on the arduino.
Now, if I did this a lot, I would definatly get some of the stickers from adafruit , but I don't, so instead, I also grab the datasheets from the Documents section at http://www.atmel.com/devices/atmega328p.aspx. Then, using a pdf-reader, I zoom in on the pin-layout, and hold the breadboard so the chip faces the same direction.

Then, I first connect the groundrails on the breadboard to both gnd pins, and the powerrails to vcc and avcc
And then, it is just searching jumperwires from the list in the arduino-ide, to the pins on the breadboard. I do one at the time, so it is easier, and do reset, sck, miso, and mosi.
Then, I connect pin 9 on the arduino to tosc1, because I don't have that scheme on my screen, I can just count the pins and see if they are connected properly. then I connect ground and voltage on the breadboard to a gnd pin on the arduino, and the 5v pin.

Oh, and of course that is with the arduino not being powered. Because only after checking all the wires again, I connect the arduino to my computer.

Remember, my arduino is connected to Com4, so you may have to change that
Then, to verify arduinoisp is working and seeing the chip, I run:
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200

The sketch talks stk500v1 so we specify that, and as speed only 19200, because the sketch can't handle faster.
If it works, it should say something about the AVR device being ready. Much like your first screenshot, except it won't complain about an expected signature.

After that, I wanted to put the bootloader on, and use it as a backup in case the chip on my arduino failed, so I select my board, the serial port, and then as programmer Arduino as Isp.
Then, I clicked Burn Bootloader, and it went to do that.

Now, after that, came a lot of diagnosis, to figure out why things worked only sometimes, involving a lot of flashing, erasing, and exchanging of chips on the breadboard and the arduino, to see what worked, and what didn't. I'll save you that, cause this is long enough already! But if you really want to know how I figure it out, ask.

Anyway, knowing what I knew after that, I would recommend the following after the bootloader. Of course we can just burn the bootloader again with the IDE, but maybe for some reason that doesn't work or you don't want to use that. So I'll act like you have this nice chip with bootloader, but no ide (no idea how you compile sketches then, but I'm not going to figure out everything!)

First, I would make a copy of the contents of the chip with bootloader, so I would do either:
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -Uflash:r:"bootloader.bin":r
for making a copy in raw format, or
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -Uflash:r:"bootloader.hex":i
for a copy in intel-hex-format (or both!)

Then, if I wanted to put something on it, but keep the bootloader intact, you would go
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -D -Uflash:w:"program.hex":i

However, if there was something already on it, I would have to clear it and program the bootloader again,
so I would go:
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -e
and then
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -Uflash:w:"bootloader.bin":r
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -Uflash:w:"bootloader.hex":i

One idea I do have, is that it should be possible to blank the first one or two bytes, by writing FF (255) to them, but I haven't found a way to do that.

Anyway, now about tinyusb.
If all that works, I would pull all the cables from arduino to breadboard, but otherwise keep the breadboard the same, upload a sketch to the arduino, that did not have arduinoisp, but only the lines for 8Mhz on pin 9. disconnect the arduino, and replace the pin 9 to tosc1 cable.

Then, I would connect the 6-pin cable to the breadboard, at the right places. 'But,' I hear you think 'I have no idea what the connections re on the cable'.
Well, don't worry! Again, if I did this a lot, I would make a cable like this: http://forums.adafruit.com/viewtopic.php?f=44&t=20284 because the colours are pretty.

However, you could also use one of the breadboard-breakout-thingies you can find at http://arduino.cc/en/Main/Standalone
For now though, that page is handy for another reason. If you have wired up your 6-pin cable correctly and connected it correctly to your usbtinyisp, it has a picture of the cable from the bottom, so you can see which is pin 1 and so on, and below that, a similar image with labels that show what the pin-layout is.
So with that, you can connect miso, mosi, reset and sck to the same places you connected them from the arduino, and vcc and gnd to the rails on your breadboard.

The avrdude commands should then be the same, except that the protocol etc is different, so for example, instead of
avrdude -pm328p -cstk500v1 -P\\.\COM4 -b19200 -e
you would write
avrdude -pm328p -cusbtiny -e

If you have more questions, or need help, post, and if things work like I said, feel free to write that too, so I know I didn't write all this for nothing (but really so other people will know it does actually work)
Posts: 66
Joined: Thu Jul 12, 2012 5:19 pm

Please be positive and constructive with your questions and comments.