Sketch to detect Atmega chip types

Following on from this thread:

There was discussion there about detecting what processor you had, from within a sketch.

I thought it would be nice to detect the processor type without having to actually upload a sketch. This project is the result of that.

First I made up a slightly modified 6-pin IDC cable, so that it would be easy to connect the board with the sketch to the board under test:

Next, after reading the datasheets at some length, I made a sketch that puts the target chip into serial programming mode and interrogates it.

The result of the interrogation is shown below:

Atmega chip detector.
Entered programming mode OK.
Signature = 1E 95 0F 
Processor = ATmega328P
Flash memory size = 32768
LFuse = FF 
HFuse = DE 
EFuse = FD 
Lock byte = CF 
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Bootloader:

7E00: 11 24 84 B7 14 BE 81 FF E6 D0 85 E0 80 93 81 00 
7E10: 82 E0 80 93 C0 00 88 E1 80 93 C1 00 86 E0 80 93 
...
7FE0: E7 DF 80 32 09 F0 F7 DF 84 E1 DA CF 1F 93 18 2F 
7FF0: DF DF 11 50 E9 F7 F4 DF 1F 91 08 95 FF FF FF FF 

MD5 sum of bootloader = 0F 02 31 72 95 C8 F7 FD 1B B7 07 17 85 A5 66 87 

First 256 bytes of program memory:

0: 0C 94 35 00 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 
10: 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 
20: 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 
30: 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 
40: 0C 94 80 03 0C 94 5D 00 0C 94 C9 00 0C 94 5D 00 
50: 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 0C 94 5D 00 
60: 0C 94 5D 00 0C 94 5D 00 E5 01 11 24 1F BE CF EF 
70: D8 E0 DE BF CD BF 11 E0 A0 E0 B1 E0 E0 E9 F8 E0 
80: 02 C0 05 90 0D 92 A2 32 B1 07 D9 F7 11 E0 A2 E2 
90: B1 E0 01 C0 1D 92 A2 3C B1 07 E1 F7 10 E0 CA E6 
A0: D0 E0 04 C0 22 97 FE 01 0E 94 42 04 C8 36 D1 07 
B0: C9 F7 0E 94 1F 02 0C 94 46 04 0C 94 00 00 08 95 
C0: FF 92 0F 93 1F 93 06 EA 11 E0 C8 01 40 E0 52 EC 
D0: 61 E0 70 E0 0E 94 FA 00 C8 01 0E 94 44 03 C8 01 
E0: 60 E0 71 E0 0E 94 75 03 91 E2 F9 2E E0 E0 F0 E0 
F0: F0 92 57 00 E4 91 C8 01 6E 2F 40 E1 50 E0 0E 94

We can find out the signature bytes, and deduce from those how much memory the chip has (by a table lookup).

Also we can find out the fuse and lock bytes.

Then the sketch reads in the entire bootloader and takes an MD5 sum of it. The idea of that is that you can use the MD5 sum as a "signature" of the bootloader, and thus quickly see what bootloader is installed.

Then the first 256 bytes of ordinary program memory are displayed, perhaps to help you confirm whether you have a sketch there or not. For production environments you could sumcheck that as well if you wanted to.

This sketch does not require avrdude, as it is entirely self-contained. All you need is a terminal to view the output.

Code, wiring, photos, example output here:

Again well done Nick!, your productivity still amazes me :slight_smile:

Agree with Rob! Awesome!