Setting Fuses and Uploading Sketches to an ATtiny841

Hi all

I've run into a problem (or two) setting fuses and uploading sketches to some attiny841 based boards I had made around 3 years ago. Initially, back then all was fine and despite some teething troubles, see,

841- Can't upload sketches

all was soon sorted and everything was fine, but after about 6 months I stopped using the boards.

Now, here we are a couple of years down the line I want to use the same sketches on the same boards again. In the interim, my pc has been rebuilt (Win 10) and the IDE is now up to 1.8.8. (I don't remember what the IDE version was before). So, to set up again, I first downloaded the latest ATtiny841 cores from github, as the cores I had before got lost when the pc was rebuilt.

The problems then started!

Problem #1. All the IDE "Tools" options have changed from the notes I made a few years back (using the older 841 cores). I have a choice of using ArduinoISP (preferred) or a temperamental USBasp for uploading but neither work. Using the Arduino as ISP to set the fuses by "burning bootloader" I get the following error message:

Arduino: 1.8.8 (Windows 10), Board: "ATtiny441/841 (No bootloader), ATtiny841, Disabled, 8 MHz (internal), EEPROM retained, B.O.D. Enabled (1.8v), B.O.D. Disabled, B.O.D. Disabled, Clockwise (like Rev. D boards), Master Only"

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf -v -pattiny841 -carduino -PCOM4 -b19200 -e -Uefuse:w:0b11111110:m -Uhfuse:w:0b11010110:m -Ulfuse:w:0xE2:m 

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         Setting bit clk period        : 5.0
         AVR Part                      : ATtiny841
         Chip Erase delay              : 15000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65    12    32    0 yes      8192   16    512  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

So, I have double, and triple checked the connections and they are all ok.

After numerous failed attempts (involving every combination I could think of for the "Tools" parameters, 841 with optiboot, 841 without optiboot, using Arduino as ISP, using Arduino as ISP(attinycore)) I still can't get the fuses set >:(

Problem #2 is even weirder. I still had a few boards that had their fuses set ok previously and I was able to upload one of the original sketches to them successfully - or so I thought, Seems PWM is no longer functioning on pins PA3 and PA6. So - what's changed in the cores (if that's where the problem(s) lie) over the last few years that could explain either, or both, of these problems? Which Tools parameters should I be using?

TIA

STDummy:
Problem #2 is even weirder. I still had a few boards that had their fuses set ok previously and I was able to upload one of the original sketches to them successfully - or so I thought, Seems PWM is no longer functioning on pins PA3 and PA6. So - what's changed in the cores (if that's where the problem(s) lie) over the last few years that could explain either, or both, of these problems? Which Tools parameters should I be using?

Please post the code you're using to test the PWM on the pins.

Device signature 0x000000 indicates either a wiring error, or that the fuses are set to use a crystal, but no crystal is present, hence there's no clock signal and the chip can't receive or respond to the programming commands.

If you try to bootload a chip without a crystal, but have selected option to use a crystal, you'll see this error in the bootloading process, which first sets the fuses, then exits programming mode (latching the fuses), then tries to reenter it to write the bootloader to flash, at which point it fails with this error because now the fuses are set to use a crystal that isn't present.

@ pert - I'll post the sketch in a little while

@DrAzzy

I don't think the fuses are set for a crystal, they are virgin from the factory.

I've taken a screenshot of the Tools settings I have used (attached).

Can you remind me, how should I have the chip wired to set the fuses? The chip is the 20 pin surface mount package. I currently have it wired exactly the same way as I have it wired for programming (which works perfectly on the chips that have the fuses already set).

i.e.
VCC - Vcc
MOSI - PA6 (programming pin 4, physical pin 16)
MISO - PA5 (5, 20)
SCK - PA4 (6, 1)
RST - RESET (-, 13)
GND - Gnd (-, 8 )

As I say, programming works ok, but setting the fuses?

Regarding the programming working ok, I'm still investigating why PA3 and PA6 are no longer acting as PWM pins, but work fine as digital. I'll post an example sketch that shows the problem (at least it does on my boards!)

OK, as promised, here's the test program I managed to upload to one of the 841 based boards that had had the fuses set (for 8mHz internal) a couple of years ago. However, as you can see HERE, two of the 6 supposedly PWM pins (PA3 and PA6) are not functioning as such.

The test sketch I used is here:

static const byte PB2Led = 2;
static const byte PA3Led = 7;
static const byte PA4Led = 6;
static const byte PA5Led = 5;
static const byte PA6Led = 4;
static const byte PA7Led = 3;

#define UP 0
#define DOWN 1

const int minPWM = 0;       // constants for min and max PWM
const int maxPWM = 255;

byte fadeDirection = UP;    // State Variable for Fade Direction
int fadeValue = 0;          // Global Fade Value
byte fadeIncrement = 5;     // How smooth to fade?
unsigned long previousFadeMillis; // millis() timing Variable, just for fading
int fadeInterval = 50;     // How fast to increment?

void setup() {
  pinMode(PB2Led, OUTPUT);
  pinMode(PA3Led, OUTPUT);
  pinMode(PA4Led, OUTPUT);
  pinMode(PA5Led, OUTPUT);
  pinMode(PA6Led, OUTPUT);
  pinMode(PA7Led, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();
  ledPulse(currentMillis);
}

void ledPulse(unsigned long thisMillis) {
  unsigned long fadeCurrentMillis = millis();
  // is it time to update yet?
  // if not, nothing happens
  if (thisMillis - previousFadeMillis >= fadeInterval) {
    // yup, it's time!
    if (fadeDirection == UP) {
      fadeValue = fadeValue + fadeIncrement;
      if (fadeValue >= maxPWM) {
        // At max, limit and change direction
        fadeValue = maxPWM;
        fadeDirection = DOWN;
      }
    } else {
      //if we aren't going up, we're going down
      fadeValue = fadeValue - fadeIncrement;
      if (fadeValue <= minPWM) {
        // At min, limit and change direction
        fadeValue = minPWM;
        fadeDirection = UP;
      }
    }
    // Only need to update when it changes
    analogWrite(PB2Led, fadeValue);
    analogWrite(PA3Led, fadeValue);
    analogWrite(PA4Led, fadeValue);
    analogWrite(PA5Led, fadeValue);
    analogWrite(PA6Led, fadeValue);
    analogWrite(PA7Led, fadeValue);
    // reset millis for the next iteration (fade timer only)
    previousFadeMillis = thisMillis;
  }
}

Those two pins definitely performed PWM functions on boards I programmed back before I updated my IDE and ATTiny cores.

I've created a github issue relating to the PWM pin issue. PWM issue on attiny 841/441 · Issue #302 · SpenceKonde/ATTinyCore · GitHub

Uhm - actually, as a sanity check - do you have the right pinmapping selected? Your sketch is meant for the counterclockwise pin mapping.

One of the recent additions was of a clockwise 841 pin numbering option (which is more sensible inn general, for a number of reasons). If you had selected that, your pin numbers wouldn't be matching reality, so you'd be operating on different pins than you thought you were.

Edit: Github issue closed, saw the upload log above that showed you are using Clockwise pin mapping, but Counterclockwise mapping pin numbers. You can use the PIN_xn defines (where x is the letter of the port, and n is the pin within that port, for example PIN_B2) to refer to pins based on port/pin (not to be confused with PINxn, which is a compiler-provided define equal to n for doing, ex, PINB=1<<PINB2; to toggle pin B2)

I'm not sure I follow what you mean here DrAzzy. I have got Pin Mapping set to Counter Clockwise (like old ATTiny Core) as the pin mapping I used for my previous boards (and have screen printed to match) is:

Pin ID, Prog Pin, SMD Chip Pins

RESET - 13
GND - 8
PB2 2 14
PB1 1 12
PB0 0 11
PA3 7 2
PA4 6 1
PA5 5 20
PA6 4 16
PA7 3 15
PA0 10 5
PA1 9 4
PA2 8 3
VCC - 9

which seems to align with the mapping in the OLD_PINOUT in the ATTinyCore/avr/cores/tinymodern/ core_pins.h file.

My main concern though, is I can't work out how to set the fuses.
Using the arduino as ISP I get this error message:

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         Setting bit clk period        : 5.0
         AVR Part                      : ATtiny841
         Chip Erase delay              : 15000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65    12    32    0 yes      8192   16    512  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: stk500_recv(): programmer is not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.

Error while burning bootloader.

and using a USBasp I get:

Arduino: 1.8.8 (Windows 10), Board: "ATtiny441/841 (No bootloader), ATtiny841, Disabled, 8 MHz (internal), EEPROM retained, B.O.D. Enabled (1.8v), B.O.D. Disabled, B.O.D. Disabled, Clockwise (like Rev. D boards), Master Only"

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf -v -pattiny841 -cusbasp -e -Uefuse:w:0b11111110:m -Uhfuse:w:0b11010110:m -Ulfuse:w:0xE2:m 

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : usbasp
         Setting bit clk period        : 5.0
         AVR Part                      : ATtiny841
         Chip Erase delay              : 15000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65    12    32    0 yes      8192   16    512  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: set SCK frequency to 187500 Hz
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Error while burning bootloader.

What on earth am I doing wrong - for both problems?! Thanks for your help so far!!

Oh, so you're getting that even with counterclockwise selected? I'll reopen the github issue then.

Initialization failed indicates a wiring error - check continuity, and check that none of the pins are shorted to eachother, ground, or vcc.

I've triple checked my wiring and couldn't find anything wrong. However, I tried to "burnbootloader again, with no power to the chip, realised my mistake and tried again with the power on - and got this result again:

Arduino: 1.8.8 (Windows 10), Board: "ATtiny441/841 (No bootloader), ATtiny841, Disabled, 8 MHz (internal), EEPROM retained, B.O.D. Enabled (1.8v), B.O.D. Disabled, B.O.D. Disabled, Clockwise (like Rev. D boards), Master Only"

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf -v -pattiny841 -carduino -PCOM4 -b19200 -e -Uefuse:w:0b11111110:m -Uhfuse:w:0b11010110:m -Ulfuse:w:0xE2:m 

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Bernie\Documents\Arduino\hardware\ATTinyCore\avr/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         Setting bit clk period        : 5.0
         AVR Part                      : ATtiny841
         Chip Erase delay              : 15000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65    12    32    0 yes      8192   16    512  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Different, but still not setting the fuses :slightly_frowning_face:

Could you have previously attempted to bootload it with a crystal clock source selected? If you do that, it will set the fuses to use a crystal. But with no crystal present, it won't run at all, including to reprogram it.

I have confirmed that PA3 and PA6 don't have working PWM.

I've fixed the issue with PWM on those pins. When I moved tone to timer2 by default, I didn't realize that the initialization code needed to change to ensure that timer1 was initialized properly, and not improperly reinitialize timer 2.

Change is in github, but not yet in board manager release.

You're my hero DrAzzy! You've proved to me that I'm not as dumb as I thought I was! Many thanks for sorting the PWM issue. I would have never found that in a month of Sundays.

Now, if you want to be my Super Hero :wink: , please can you remind me of:

a) The precise method of burning the fuses on an 841 using ICSP and Arduino as ISP? My boards have ICSP pins on them so I have been connecting them to the ICSP pins on a Arduino UNO board running ArduinoISP and with the normal Tools settings (see post #3), simply selecting Burn Bootloader. I used to be able to do this with no problem when I had my 861 based boards made a few years back, but now I seem to be just bricking them.

b) How can I recover the aforementioned bricked boards? I don't have a crystal but I do have a version of ArduinoISP with an 8mHz signal available on one of the pins.

If you can solve these issues then you will be raised to Arduino God like status in my eyes, and be saving me a whole load of heartache 'cos at the moment I own around 80 paperweights instead of working boards!!!

a) is correct. I do not know why that is not working; that works for me. The only way that you can brick a chip burning bootloader such that it gives 0x000000 signature is if you set it to use an external crystal (and don't have one connected). Do you see it writing fuses and then failing the first time you bootload it?

b) Put the 8MHz clock line onto PB0, and that should revive a chip that has been set to use a crystal when no crystal is present.

Well, this is odd!

I started afresh this morning to see if I had missed a connection or something (I hadn't) and so decided to screen shot the error message again.

So, grab another virgin board, upload bootloader....no errors! WTF?! Ok, tried again with another board and no errors again, all is fine in the world once more. I'm now 12 boards in and all are behaving.

I have absolutely no idea what was going on yesterday, but as it ain't going on today I'm burning fuses on all 80 boards today!!

I did try unbricking the two boards that wouldn't co-operate yesterday and even with an 8mHz signal on PB0 they still won't play ball. I'm 99.9% confident that I didn't have external crystal set when all this started, if I remember rightly, they didn't even start to upload anything. I guess they could be faulty chips, but its a strange coincidence that two faulty ones on the bounce came out of the box out of a total batch of 100.

Still, all seems good now and I'll download the revised ATTinyCore before actually going on to uploading my sketch to the boards.

Thanks a million again DrAzzy, its guy's like you that make guys like me look good!!

Quick update....

All fuse burning still going well (apart from the two bricked boards, which I'll probably bin) and I can confirm that PA3 and PA6 are now fully functioning PWM pins using the revised ATTinyCore.

Many grateful thanks go to DrAzzy for sorting this so quickly!

Have some Kudos sir!!