As per data sheets of ATtiny85, the default (factory set) values of the fuse bytes are:
Fuse Lowe Byte = 0x62
Fuse High Byte = 0xDF
Fuse Extended Byte = 0xFF
I connected a brand new ATtiny85 MCU with UNO in 'In System Serial Programming' Mode and then executed the following sketch. I got FE (Self Programming Mode is enabled) and not FF (Self Programming Mode is disabled) for the value of Fuse Extended Byte. Is it OK or am I reading corrupted value? The other two fuse bytes are alright.
#include<SPI.h>
byte progEnb[] = {0xAC, 0x53, 0x00, 0x00}; //prog enable command bytes
byte fuseLCmnd[] = {0x50, 0x00, 0x00, 0x00}; //Fuse Low Byte (fac: 0x62) read command
byte fuseHCmnd[] = {0x58, 0x08, 0x00, 0x00}; //Fuse High Byte (fac: 0xDF) read command
byte fuseECmnd[] = {0x50, 0x08, 0x00, 0x00}; //Fuse Extended Byte (fac: 0xFF)--> 0xFE; read command
byte myDataL[4];
byte myDataH[4];
byte myDataE[4];
#define RSTAL 4 //active Low DPin-4 drives the RESET/-pin of ATtiny85.
#define MOSI 11
#define MISO 12
#define SCK 13
void setup()
{
Serial.begin(9600);
SPI.begin(); //PB2 - PB5 are converted to SS/(OUT-H), MOSI(OUT-L), MISO(IN), SCK(OUT-L)
bitSet(SPCR, 4); //UNO-1 is Master
SPI.setBitOrder(MSBFIRST); //bit transmission order
SPI.setDataMode(SPI_MODE0); //CPOL and CPHA (Clock polarity; Clock phase)
SPI.setClockDivider(SPI_CLOCK_DIV128); //data rate = fosc/128 = 125 kbit
bitClear(SPCR, 7); //local SPI interrupt is disable
//------------------------------------------------------
pinMode(RSTAL, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SCK, OUTPUT);
//------------------------------------------------------
mcuRST();
for (int i = 0; i < 4; i++)
{
SPDR = progEnb[i]; //SPI.transfer() does not work
while (bitRead(SPSR, 7) != HIGH)//SPIF is cleared when SPSR is read
{
;
}
}
//----------------------------------------
for (int i = 0; i < 4; i++)
{
SPDR = fuseLCmnd[i]; //SPI.transfer() does not work
while (bitRead(SPSR, 7) != HIGH)//SPIF is cleared when SPSR is read
{
;
}
myDataL[i] = SPDR;
}
//-------------------------------------------
for (int i = 0; i < 4; i++)
{
SPDR = fuseHCmnd[i]; //SPI.transfer() does not work
while (bitRead(SPSR, 7) != HIGH)//SPIF is cleared when SPSR is read
{
;
}
myDataH[i] = SPDR;
}
//-------------------------------------------
for (int i = 0; i < 4; i++)
{
SPDR = fuseECmnd[i]; //SPI.transfer() does not work
while (bitRead(SPSR, 7) != HIGH)//SPIF is cleared when SPSR is read
{
;
}
myDataE[i] = SPDR;
}
//------------------------------------------------
Serial.print("Fuse Low Byte : "); Serial.println(myDataL[3], HEX);
Serial.print("Fuse High Byte : "); Serial.println(myDataH[3], HEX);
Serial.print("Fuse Extended Byte : "); Serial.println(myDataE[3], HEX);
SPI.end();
}
void loop()
{
}
void mcuRST()
{
digitalWrite(RSTAL, LOW);
digitalWrite(SCK, HIGH);
delayMicroseconds(500);
digitalWrite(SCK, LOW);
digitalWrite(RSTAL, HIGH);
delay(50);
digitalWrite(RSTAL, LOW);
delay(50);
}