I am programming avr microcontrollers using avrgcc and avrdude . If am specifying wrong controllers then avrdude throws error message syaing wrong device signature. Is there an avrdude method from which i can find which controller is it connected to like Atmega8,Atmega324,Atmega644 etc. Then it would be easy to change the avrdude command with respect to the controller reply am getting.
Asked
Active
Viewed 1,489 times
1 Answers
1
As a first attempt, you could try this (admittedly tremendously ugly solution):
SIGNATURE=`sudo avrdude -cusbtiny -p1200 -U signature:r:-:i -F 2>/dev/null
| head -n1
| sed "s/^:[0-9A-F]\{8\}\([0-9A-F]\{6\}\)[0-9A-F]*/\1/g"
| sed "s/\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\)/0x\L\1 0x\L\2 0x\L\3/g"`
&& cat /etc/avrdude.conf
| grep "\(\<id\>\|$SIGNATURE\)"
| grep -B 1 signature
| head -n 1
| sed "s/.*\"\([a-z0-9]*\)\".*/\1/g"
It works for me on the bash prompt, with a ATtiny2313a being connected to an USBTinyISP and avrdude.conf residing at /etc/.
Let's split it up for a short explanation.
Get the device signature
sudo avrdude -cusbtiny -p1200 -U signature:r:-:i -F 2>/dev/null
Change format to match avrdude.conf
The signature is in the first line of avrdude's output:
| head -n1
Extract the 6 signature digits:
| sed "s/^:[0-9A-F]\{8\}\([0-9A-F]\{6\}\)[0-9A-F]*/\1/g"
Convert to lower case, insert "0x" and ","
| sed "s/\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\)/0x\L\1 0x\L\2 0x\L\3/g"
Extract corresponding id from avrdude.conf
Find all id lines plus our one signature line:
cat /etc/avrdude.conf
| grep "\(\<id\>\|$SIGNATURE\)"
Now extract the corresponding id line for our signature:
| grep -B 1 signature
| head -n 1
Finally, we remove everything besides the id:
| sed "s/.*\"\([a-z0-9]*\)\".*/\1/g"
The resulting output should be usable with your tools - hope that helps...

leo
- 81
- 4
-
i founded a more simple way using a tweak.In C its implemented like thiscase ATMEGA32 : sprintf(Uc,"avrdude -c usbasp -p atmega32 sig 1>hello.txt 2>>hello.txt"); sprintf(Check,"hello=`grep \"avrdude: safemode: Fuses OK\" hello.txt`"); system(Uc); stat=system(Check); if(stat == 0) return stat; printf("Status is %d \n",stat); break; – ganeshredcobra Mar 28 '14 at 12:17
-
Hmm, this only checks whether there is a atmega32 connected or not; It does not tell you what controller actually is connected. – leo Mar 31 '14 at 08:41
-
yup it only checks for atmega32 – ganeshredcobra Mar 31 '14 at 16:27