Skip to content

Commit 3836e56

Browse files
committed
Added support for ATtiny2313A, ATtiny4313, ATtiny13
1 parent 9ceea7a commit 3836e56

File tree

4 files changed

+120
-26
lines changed

4 files changed

+120
-26
lines changed

Atmega_Board_Detector/Atmega_Board_Detector.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Atmega chip fuse detector
22
// Author: Nick Gammon
3-
// Date: 9th May 2012
4-
// Version: 1.5
3+
// Date: 22nd May 2012
4+
// Version: 1.6
55

66
// Version 1.1 added signatures for Attiny24/44/84 (5 May 2012)
77
// Version 1.2 added signatures for ATmeag8U2/16U2/32U2 (7 May 2012)
88
// Version 1.3: Added signature for ATmega1284P (8 May 2012)
99
// Version 1.4: Output an 8 MHz clock on pin 9
1010
// Version 1.5: Corrected flash size for Atmega1284P.
11+
// Version 1.6: Added signatures for ATtiny2313A, ATtiny4313, ATtiny13
1112

1213
/*
1314
@@ -59,6 +60,7 @@ enum {
5960
programAcknowledge = 0x53,
6061

6162
readSignatureByte = 0x30,
63+
readCalibrationByte = 0x38,
6264

6365
readLowFuseByte = 0x50, readLowFuseByteArg2 = 0x00,
6466
readExtendedFuseByte = 0x50, readExtendedFuseByteArg2 = 0x08,
@@ -80,7 +82,7 @@ typedef struct {
8082
const unsigned long kb = 1024;
8183

8284
// see Atmega328 datasheet page 298
83-
signatureType signatures [] =
85+
const signatureType signatures [] =
8486
{
8587
// signature description flash size bootloader size
8688

@@ -120,6 +122,13 @@ signatureType signatures [] =
120122
// ATmega1284P family
121123
{ { 0x1E, 0x97, 0x05 }, "ATmega1284P", 128 * kb, 1 * kb },
122124

125+
// ATtiny4313 family
126+
{ { 0x1E, 0x91, 0x0A }, "ATtiny2313A", 2 * kb, 0 },
127+
{ { 0x1E, 0x92, 0x0D }, "ATtiny4313", 4 * kb, 0 },
128+
129+
// ATtiny13 family
130+
{ { 0x1E, 0x90, 0x07 }, "ATtiny13A", 1 * kb, 0 },
131+
123132
}; // end of signatures
124133

125134
// if signature found in above table, this is its index
@@ -344,6 +353,8 @@ void getFuseBytes ()
344353
showHex (program (readExtendedFuseByte, readExtendedFuseByteArg2), true);
345354
Serial.print ("Lock byte = ");
346355
showHex (program (readLockByte, readLockByteArg2), true);
356+
Serial.print ("Clock calibration = ");
357+
showHex (program (readCalibrationByte), true);
347358
} // end of getFuseBytes
348359

349360
void setup ()

Atmega_Board_Programmer/Atmega_Board_Programmer.ino

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Atmega chip programmer
22
// Author: Nick Gammon
3-
// Date: 9th May 2012
4-
// Version: 1.9
3+
// Date: 22nd May 2012
4+
// Version: 1.12
55

66
// Version 1.1: Reset foundSig to -1 each time around the loop.
77
// Version 1.2: Put hex bootloader data into separate files
@@ -14,6 +14,7 @@
1414
// Version 1.9: Added support for Atmega1284P, and fixed some bugs
1515
// Version 1.10: Corrected flash size for Atmega1284P.
1616
// Version 1.11: Added support for Atmega1280. Removed MD5SUM stuff to make room.
17+
// Version 1.12: Added signatures for ATtiny2313A, ATtiny4313, ATtiny13
1718

1819
/*
1920
@@ -74,6 +75,7 @@ enum {
7475
programAcknowledge = 0x53,
7576

7677
readSignatureByte = 0x30,
78+
readCalibrationByte = 0x38,
7779

7880
readLowFuseByte = 0x50, readLowFuseByteArg2 = 0x00,
7981
readExtendedFuseByte = 0x50, readExtendedFuseByteArg2 = 0x08,
@@ -194,6 +196,13 @@ signatureType signatures [] =
194196
0xFD, // fuse extended byte: brown-out detection at 2.7V
195197
0x2F }, // lock bits: SPM is not allowed to write to the Boot Loader section.
196198

199+
// ATtiny4313 family
200+
{ { 0x1E, 0x91, 0x0A }, "ATtiny2313A", 2 * kb, 0 },
201+
{ { 0x1E, 0x92, 0x0D }, "ATtiny4313", 4 * kb, 0 },
202+
203+
// ATtiny13 family
204+
{ { 0x1E, 0x90, 0x07 }, "ATtiny13A", 1 * kb, 0 },
205+
197206
}; // end of signatures
198207

199208
// if signature found in above table, this is its index
@@ -309,6 +318,8 @@ void getFuseBytes ()
309318
showHex (program (readExtendedFuseByte, readExtendedFuseByteArg2), true);
310319
Serial.print (F("Lock byte = "));
311320
showHex (program (readLockByte, readLockByteArg2), true);
321+
Serial.print ("Clock calibration = ");
322+
showHex (program (readCalibrationByte), true);
312323
} // end of getFuseBytes
313324

314325
// burn the bootloader to the target device

Atmega_Fuse_Calculator/Atmega_Fuse_Calculator.ino

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Atmega chip fuse caculator
22
// Author: Nick Gammon
3-
// Date: 9th May 2012
4-
// Version: 1.2
3+
// Date: 222nd May 2012
4+
// Version: 1.3
55

66
// Version 1.1: Output an 8 MHz clock on pin 9
77
// Version 1.2: Corrected flash size for Atmega1284P.
8+
// Version 1.3: Added signatures for ATtiny2313A, ATtiny4313, ATtiny13
89

910
/*
1011
@@ -52,6 +53,7 @@ enum {
5253
programAcknowledge = 0x53,
5354

5455
readSignatureByte = 0x30,
56+
readCalibrationByte = 0x38,
5557

5658
readLowFuseByte = 0x50, readLowFuseByteArg2 = 0x00,
5759
readExtendedFuseByte = 0x50, readExtendedFuseByteArg2 = 0x08,
@@ -64,18 +66,19 @@ enum {
6466
}; // end of enum
6567

6668
// copy of fuses/lock bytes found for this processor
67-
byte fuses [4];
69+
byte fuses [5];
6870

6971
// meaning of bytes in above array
7072
enum {
7173
lowFuse,
7274
highFuse,
7375
extFuse,
74-
lockByte
76+
lockByte,
77+
calibrationByte
7578
};
7679

7780
// handler for special things like bootloader size
78-
typedef void (*specialHandlerFunction) (const byte val, const byte mask, const unsigned int bootLoaderSize);
81+
typedef void (*specialHandlerFunction) (const byte val, const unsigned int bootLoaderSize);
7982

8083
// item for one piece of fuse information
8184
typedef struct {
@@ -102,7 +105,7 @@ char PROGMEM descOCDEnable [] = "OCD Enable";
102105
char PROGMEM descJtagEnable [] = "JTAG Enable";
103106

104107
// calculate size of bootloader
105-
void fBootloaderSize (const byte val, const byte mask, const unsigned int bootLoaderSize)
108+
void fBootloaderSize (const byte val, const unsigned int bootLoaderSize)
106109
{
107110
Serial.print (F("Bootloader size: "));
108111
unsigned int len = bootLoaderSize;
@@ -119,22 +122,22 @@ void fBootloaderSize (const byte val, const byte mask, const unsigned int bootLo
119122
} // end of fBootloaderSize
120123

121124
// show brownout level
122-
void fBrownoutDetectorLevel (const byte val, const byte mask, const unsigned int bootLoaderSize)
125+
void fBrownoutDetectorLevel (const byte val, const unsigned int bootLoaderSize)
123126
{
124127
Serial.print (F("Brownout detection at: "));
125-
switch (val)
128+
switch (val & 3)
126129
{
127-
case 0b111: Serial.println (F("disabled.")); break;
128-
case 0b110: Serial.println (F("1.8V.")); break;
129-
case 0b101: Serial.println (F("2.7V.")); break;
130-
case 0b100: Serial.println (F("4.3V.")); break;
130+
case 0b11: Serial.println (F("disabled.")); break;
131+
case 0b10: Serial.println (F("1.8V.")); break;
132+
case 0b01: Serial.println (F("2.7V.")); break;
133+
case 0b00: Serial.println (F("4.3V.")); break;
131134
default: Serial.println (F("reserved.")); break;
132135
} // end of switch
133136

134137
} // end of fBrownoutDetectorLevel
135138

136139
// show brownout level (alternative)
137-
void fBrownoutDetectorLevelAtmega8U2 (const byte val, const byte mask, const unsigned int bootLoaderSize)
140+
void fBrownoutDetectorLevelAtmega8U2 (const byte val, const unsigned int bootLoaderSize)
138141
{
139142
Serial.print (F("Brownout detection at: "));
140143
switch (val)
@@ -151,7 +154,7 @@ void fBrownoutDetectorLevelAtmega8U2 (const byte val, const byte mask, const uns
151154
} // end of fBrownoutDetectorLevelAtmega8U2
152155

153156
// show clock start-up times
154-
void fStartUpTime (const byte val, const byte mask, const unsigned int bootLoaderSize)
157+
void fStartUpTime (const byte val, const unsigned int bootLoaderSize)
155158
{
156159
Serial.print (F("Start-up time: SUT0:"));
157160
if ((val & 1) == 0) // if zero, the fuse is "programmed"
@@ -167,7 +170,7 @@ void fStartUpTime (const byte val, const byte mask, const unsigned int bootLoade
167170
} // end of fStartUpTime
168171

169172
// work out clock source
170-
void fClockSource (const byte val, const byte mask, const unsigned int bootLoaderSize)
173+
void fClockSource (const byte val, const unsigned int bootLoaderSize)
171174
{
172175
Serial.print (F("Clock source: "));
173176
switch (val)
@@ -296,6 +299,46 @@ fuseMeaning PROGMEM ATmega164P_fuses [] =
296299

297300
}; // end of ATmega164P_fuses
298301

302+
fuseMeaning PROGMEM ATtiny4313_fuses [] =
303+
{
304+
{ extFuse, 0x01, descSelfProgrammingEnable },
305+
306+
{ highFuse, 0x80, descDebugWireEnable },
307+
{ highFuse, 0x40, descEEPROMsave },
308+
{ highFuse, 0x20, descSerialProgrammingEnable },
309+
{ highFuse, 0x10, descWatchdogTimerAlwaysOn },
310+
{ highFuse, 0x01, descExternalResetDisable },
311+
312+
{ lowFuse, 0x80, descDivideClockBy8 },
313+
{ lowFuse, 0x40, descClockOutput },
314+
315+
// special (combined) bits
316+
{ lowFuse, 0x30, NULL, fStartUpTime },
317+
{ lowFuse, 0x0F, NULL, fClockSource },
318+
319+
{ highFuse, 0x0E, NULL, fBrownoutDetectorLevel },
320+
321+
}; // end of ATtiny4313_fuses
322+
323+
fuseMeaning PROGMEM ATtiny13_fuses [] =
324+
{
325+
{ highFuse, 0x10, descSelfProgrammingEnable },
326+
{ highFuse, 0x08, descDebugWireEnable },
327+
{ highFuse, 0x01, descExternalResetDisable },
328+
329+
{ lowFuse, 0x80, descSerialProgrammingEnable },
330+
{ lowFuse, 0x40, descEEPROMsave },
331+
{ lowFuse, 0x20, descWatchdogTimerAlwaysOn },
332+
{ lowFuse, 0x10, descDivideClockBy8 },
333+
334+
// special (combined) bits
335+
{ lowFuse, 0x0C, NULL, fStartUpTime },
336+
{ lowFuse, 0x03, NULL, fClockSource },
337+
338+
{ highFuse, 0x06, NULL, fBrownoutDetectorLevel },
339+
340+
}; // end of ATtiny13_fuses
341+
299342
// structure for information about a single processor
300343
typedef struct {
301344
byte sig [3];
@@ -309,7 +352,7 @@ typedef struct {
309352
const unsigned long kb = 1024;
310353

311354
// see Atmega328 datasheet page 298
312-
signatureType signatures [] =
355+
const signatureType signatures [] =
313356
{
314357
// signature description flash size bootloader size
315358

@@ -349,6 +392,13 @@ signatureType signatures [] =
349392
// ATmega1284P family
350393
{ { 0x1E, 0x97, 0x05 }, "ATmega1284P", 128 * kb, 1 * kb, ATmega164P_fuses, NUMITEMS (ATmega164P_fuses) }, // same as ATmega164P
351394

395+
// ATtiny4313 family
396+
{ { 0x1E, 0x91, 0x0A }, "ATtiny2313A", 2 * kb, 0, ATtiny4313_fuses, NUMITEMS (ATtiny4313_fuses) },
397+
{ { 0x1E, 0x92, 0x0D }, "ATtiny4313", 4 * kb, 0, ATtiny4313_fuses, NUMITEMS (ATtiny4313_fuses) },
398+
399+
// ATtiny13 family
400+
{ { 0x1E, 0x90, 0x07 }, "ATtiny13A", 1 * kb, 0, ATtiny13_fuses, NUMITEMS (ATtiny13_fuses) },
401+
352402
}; // end of signatures
353403

354404
// if signature found in above table, this is its index
@@ -481,7 +531,17 @@ void showFuseMeanings ()
481531

482532
// some fuses use multiple bits so we'll call a special handling function
483533
if (thisFuse.specialHandler)
484-
thisFuse.specialHandler (fuses [val] & mask, mask, signatures [foundSig].baseBootSize);
534+
{
535+
// get value into low-order bits
536+
byte adjustedVal = fuses [val] & mask;
537+
while ((mask & 1) == 0)
538+
{
539+
adjustedVal >>= 1;
540+
mask >>= 1;
541+
}
542+
543+
thisFuse.specialHandler (adjustedVal, signatures [foundSig].baseBootSize);
544+
} // end if special handler
485545

486546
} // end of for each fuse meaning
487547

@@ -493,6 +553,7 @@ void getFuseBytes ()
493553
fuses [highFuse] = program (readHighFuseByte, readHighFuseByteArg2);
494554
fuses [extFuse] = program (readExtendedFuseByte, readExtendedFuseByteArg2);
495555
fuses [lockByte] = program (readLockByte, readLockByteArg2);
556+
fuses [calibrationByte] = program (readCalibrationByte);
496557

497558
Serial.print ("LFuse = ");
498559
showHex (fuses [lowFuse], true);
@@ -502,6 +563,9 @@ void getFuseBytes ()
502563
showHex (fuses [extFuse], true);
503564
Serial.print ("Lock byte = ");
504565
showHex (fuses [lockByte], true);
566+
Serial.print (F("Clock calibration = "));
567+
showHex (fuses [calibrationByte], true);
568+
505569
} // end of getFuseBytes
506570

507571
void setup ()

Atmega_Hex_Uploader/Atmega_Hex_Uploader.ino

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Atmega hex file uploader (from SD card)
22
// Author: Nick Gammon
3-
// Date: 11th May 2012
4-
// Version: 1.8 // NB update 'Version' variable below!
3+
// Date: 22nd May 2012
4+
// Version: 1.10 // NB update 'Version' variable below!
55

66
// Version 1.1: Some code cleanups as suggested on the Arduino forum.
77
// Version 1.2: Cleared temporary flash area to 0xFF before doing each page
@@ -15,6 +15,7 @@
1515
// Added "L" command (list directory)
1616
// Version 1.9: Ensure in programming mode before access flash (eg. if reset removed to test)
1717
// Added reading of clock calibration byte (note: this cannot be changed)
18+
// Version 1.10: Added signatures for ATtiny2313A, ATtiny4313, ATtiny13
1819

1920
/*
2021
@@ -54,7 +55,7 @@
5455

5556
// #include <memdebug.h>
5657

57-
const char Version [] = "1.9";
58+
const char Version [] = "1.10";
5859

5960
// bit banged SPI pins
6061
const byte MSPIM_SCK = 4; // port D bit 4
@@ -145,7 +146,7 @@ const byte NO_FUSE = 0xFF;
145146

146147

147148
// see Atmega datasheets
148-
signatureType PROGMEM signatures [] =
149+
const signatureType PROGMEM signatures [] =
149150
{
150151
// signature description flash size bootloader flash fuse
151152
// size page to
@@ -188,6 +189,13 @@ signatureType PROGMEM signatures [] =
188189
// ATmega1284P family
189190
{ { 0x1E, 0x97, 0x05 }, "ATmega1284P", 128 * kb, 1 * kb, 256, highFuse },
190191

192+
// ATtiny4313 family
193+
{ { 0x1E, 0x91, 0x0A }, "ATtiny2313A", 2 * kb, 0, 32, NO_FUSE },
194+
{ { 0x1E, 0x92, 0x0D }, "ATtiny4313", 4 * kb, 0, 64, NO_FUSE },
195+
196+
// ATtiny13 family
197+
{ { 0x1E, 0x90, 0x07 }, "ATtiny13A", 1 * kb, 0, 32, NO_FUSE },
198+
191199
}; // end of signatures
192200

193201
char name[MAX_FILENAME] = { 0 }; // current file name

0 commit comments

Comments
 (0)