Pages: [1]   Go Down
Author Topic: ATtiny84 & <avr/fuse.h>, fuses automatically programmed?  (Read 600 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 15
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am programming a set of ATtiny84Vs using WinAVR. I am using the makefile from the WinAVR Makefile generator, which is attached below since it is too big to post.

I wish to use the macros in the <avr/fuse.h> header file to set the fuses in code for my set of ATtinys, rather than program them individually using avrdude. For example:
Code:
// Fuse settings
FUSES =
{
.low =  (FUSE_CKDIV8 & FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0),
.high = (FUSE_SPIEN),
.extended = (EFUSE_DEFAULT),
};
In particular, I am changing the SUT (Start Up Time) fuse bits to a shorter startup than the default (4 ms instead of 64 ms).

If I have this in my code and compile it with "make all", then use "make program" to upload it to my uC, will the fuses be appropriately programmed? Do I need to add something to my makefile in order to program the fuse bits? Or do I just have to do it manually with the AVRdude terminal?

Relavent section from the makefile:
Code:
#---------------- Programming Options (avrdude) ----------------

# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = avrisp

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com3

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS +=-b 19200
Code:
# Program the device. 
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
In particular, I see -U flags for the flash and eeprom, but not any of the fuse bits. Do I need to add these flags myself in order to program the fuse bits?

The documentation at the avr-libc page (http://www.nongnu.org/avr-libc/user-manual/group__avr__fuse.html) says:
Quote
Programming tools can take advantage of the fuse information embedded in the ELF file, by extracting this information and determining if the fuses need to be programmed before programming the Flash and EEPROM memories. This also allows a single ELF file to contain all the information needed to program an AVR.
This seems to say that you can set the programmer up to automatically program the fuses, but it doesn't tell how. Does anyone ave any experience in this area?

* Makefile (17.11 KB - downloaded 5 times.)
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1730
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The only way to program the fuses is by ISP or HVSP. It is not possible to do it from code running on the microcontroller.

You can however do it in the makefile:
Code:
#How to program the fuses
AVRDUDE_WRITE_FUSES = -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
#Set up your fuse values:
HFUSE = ...
LFUSE = ...
EFUSE = ...

# Program the device.  
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSES) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
« Last Edit: July 07, 2014, 02:48:51 am by Tom Carpenter » Logged

~Tom~

Offline Offline
God Member
*****
Karma: 15
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found something in the last post of this thread here on AVR Freaks: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=69013&postdays=0&postorder=asc&start=40

It seems to work well. Thanks anyway, Tom.
Logged

Pages: [1]   Go Up
Jump to: