Friday 6 December 2019

arduino - ATtiny2313 refuses to be programmed after setting CPU clock to 500kHz


The other day I was writing a program for an ATtiny2313. Once it worked I decided to test it at the various clock speeds that are available and programmed through setting the LFUSE as described on page 159.



  • The default clock speed is 1MHz;

  • so I tried 8MHz next and all worked fine;


  • Then I set the clock speed for 4MHz with the /8-prescaler resulting in 500kHz clock.


Although the controller runs the program at the expected speed, my programmer refuses to reprogram the controller since. avrdude (5.11.1) just throws the well known: 'Yikes!':


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

I tried adding the -F flag, but of course that didn't either.


Here are some code sniplets I used and changed the clock speed as expected:



// 0.5MHz
FUSES = { .low = 0x62 , .high = HFUSE_DEFAULT , .extended = EFUSE_DEFAULT , };


// 1MHz (default)
FUSES = { .low = 0x64 , .high = HFUSE_DEFAULT , .extended = EFUSE_DEFAULT , };

// 8MHz
FUSES = { .low = 0xe4 , .high = HFUSE_DEFAULT , .extended = EFUSE_DEFAULT , };


For programming, I use an Arduino with the ArduinoISP (version 04m3) sketch that came with Arduino IDE 1.0.1.


This is the command to program flash:


avrType=attiny2313
avrFreq=1000000
programmerDev=/dev/ttyUSB003
programmerType=arduino
avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U flash:w:$(src).flash.hex

This is the command to program the fuses:


avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U lfuse:w:$(src).lfuse.hex


My question is twofold:



  1. What is the reason I cannot program the controller after setting it to 500kHz clock (while the program in the controller seems to run just fine);

  2. What are my options for reprogramming the fuses without using a HV-programmer? Did I perhaps miss any useful flags to avrdude?


BTW: Had the same issue once with an ATtiny45 @ 128kHz. HV-programming solves it, but I want to prevent the HV situation.



Answer



The issue, as explained, too high SPI clock frequency. There exists a fixed version of ArduinoISP that can program at lower frequency available here. Some discussion on topic is available here.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...