Author Topic: Can't program ATmega32U4 after setting CKDIV8 = 1  (Read 1536 times)

0 Members and 1 Guest are viewing this topic.

Offline avf32Topic starter

  • Newbie
  • Posts: 9
  • Country: gb
Can't program ATmega32U4 after setting CKDIV8 = 1
« on: August 29, 2021, 12:33:57 pm »
Hi all,

My ATmega32U4 adventure continues...  Everything was working fine until I tried to set the CKDIV8 bit in LFUSE to 1.

After this, I can no longer program it, it just says "target doesn't answer".  I've double-checked all the connections, and I'm pretty sure that I didn't change any other fuse bits when trying to set CKDIV8 (I set LFUSE to 0xD2, it was 0x52 before that).

Is this expected?  Can I recover from this somehow?  Is it bricked?

Thanks,
Alex
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #1 on: August 29, 2021, 01:08:31 pm »
I guess you have to lower the ISP clock rate; in avrdude by setting the -B flag to 8 or 16
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #2 on: August 29, 2021, 01:42:19 pm »
I guess you have to lower the ISP clock rate; in avrdude by setting the -B flag to 8 or 16

As HB9EVI says you have to lower your programming speed.
The AVR supports a Max programming speed of MCU-Freq/4 , so if you had an 8MHz clock , and divide by 8 ==> 1MHz , then Max programming speed is 1MHz/4 ==> 250KHz

/Bingo
 

Offline avf32Topic starter

  • Newbie
  • Posts: 9
  • Country: gb
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #3 on: August 29, 2021, 01:56:22 pm »
Thanks both.  I saw that suggestion elsewhere on the Internet, and I've tried with various values for -B (including 8 and 16), and it makes no difference.

I do get a warning from avrdude:

avrdude: set SCK frequency to 32000 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.

I suspect this might be why -B doesn't seem to do anything?  Other sources say that this is because I have a USBASP with Chinese firmware which autodetects the programming speed?  Is it autodetecting incorrectly in my case, and ignoring the -B option?  I have a second USBASP on order, so I'll be able to flash that to stock firmware to see if that helps.

However, I unprogrammed the CKDIV8 bit (= 1), so as I understand it, that should have increased the frequency from 1MHz (internal 8MHz oscillator divided by 8) to 8MHz, rather than decreasing it.
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 7765
  • Country: de
  • A qualified hobbyist ;)
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #4 on: August 29, 2021, 02:25:59 pm »
The fuse bits can be a bit confusing. The default for CKDIV8 is 0 (programmed, enabled). So setting it to 1 (unprogrammed) will disable the 8:1 prescaler. Old USBasp firmwares don't support the low-SCK function, but you can update the firmware: https://blog.podkalicki.com/how-to-update-avr-usbasp-firmware-to-latest-version/
 

Offline avf32Topic starter

  • Newbie
  • Posts: 9
  • Country: gb
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #5 on: August 29, 2021, 02:37:14 pm »
The fuse bits can be a bit confusing. The default for CKDIV8 is 0 (programmed, enabled). So setting it to 1 (unprogrammed) will disable the 8:1 prescaler.

Thanks.

Yes, I was setting it to 1 (unprogrammed) to disable the prescaler -- that was my intention.

I guess I'll wait until I get the second USBASP so that I can change the firmware and see if that makes any difference.
 

Offline avf32Topic starter

  • Newbie
  • Posts: 9
  • Country: gb
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #6 on: September 09, 2021, 02:46:46 pm »
Got my new USBASP.  Whatever firmware it's running, I don't get the "cannot set sck period" warning with it.

I've tried different values for -B, and still nothing:


$ avrdude -B 16 -p m32u4

avrdude: set SCK frequency to 32000 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.


Is it worth trying to flash the stock firmware onto one of my USBASPs and try again?  I'm not sure what else to try, except buying a new chip, which seems ridiculous.  Any ideas appreciated!

Thanks!
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #7 on: September 10, 2021, 09:43:40 am »
Perhaps you inadvertently wrote to the SPIEN fuse and disabled the SPI interface?  If so you'll need a high voltage programmer to recover it.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #8 on: September 20, 2021, 02:04:21 pm »
The whole concept of those confusing bits is indeed quite ridiculous.
 At some time it will bite several hours out of the time of each and every developer who works with the AVR chips.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: Can't program ATmega32U4 after setting CKDIV8 = 1
« Reply #9 on: September 20, 2021, 02:11:55 pm »
The whole concept of those confusing bits is indeed quite ridiculous.
 At some time it will bite several hours out of the time of each and every developer who works with the AVR chips.
Yes - the biggest problem with the AVR interface is that it needs a clock to do ISP - this is the root cause of most of these problems as multiple things can cause teh clock to either not be there or be the wrong speed.
Atmel really didn't understand the needs of production programming, as evidenced by how long it took to include the config fuses in the hex file.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf