81
Embedded development / Re: Setting AVR Fuses in C code
« Last post by Pecan on April 11, 2024, 06:03:57 pm »Do a google lookup of "ATMEGA328P Datasheet" or any datasheet of the chip you're interested in.
I haven't done embedded programming for years now (since 2019), so my knowledge of the newer chips is more than rusty.
Lately I've found ChatGPT to be quite helpful if you tightly focus your query (prompt) and *always* verify the answer.
On a wider focused query I've found ChatGPT will make anything up when it does not have specific training on the subject. It has never said, "I don't know" when it should.
You can always ask it where it got the information. Then follow up with your own verification.
For example:
I haven't done embedded programming for years now (since 2019), so my knowledge of the newer chips is more than rusty.
Lately I've found ChatGPT to be quite helpful if you tightly focus your query (prompt) and *always* verify the answer.
On a wider focused query I've found ChatGPT will make anything up when it does not have specific training on the subject. It has never said, "I don't know" when it should.
You can always ask it where it got the information. Then follow up with your own verification.
For example:
Code
User
Where can I get more information on the fuse structure code?
ChatGPT
To get more detailed information on the fuse structure and the fuse settings for Atmel AVR microcontrollers, you can refer to the following resources:
Atmel AVR Datasheets
The most comprehensive source of information on fuse bits and their meanings is the Atmega328P datasheet. The datasheet provides detailed explanations of each fuse bit and its effect on the microcontroller's operation.
You can download the Atmega328P datasheet from the Microchip Technology website:
Atmega328P Datasheet
AVR Libc Documentation
AVR Libc is a library of standard C functions for Atmel AVR microcontrollers. The documentation provides detailed information on the predefined fuse settings and the fuse structure.
You can find the AVR Libc documentation here:
AVR Libc Documentation
AVRDUDE
AVRDUDE is a command-line utility for programming Atmel AVR microcontrollers. It supports reading and writing fuse settings and provides a list of available fuse bits and their meanings.
You can find more information about AVRDUDE and its supported commands here:
AVRDUDE Documentation
Example Code
Here is an example of how the fuse settings are typically defined in Atmel AVR programming:
c
Copy code
#include <avr/io.h>
FUSES = {
.low = (LFUSE_DEFAULT & ~FUSE_CKDIV8 & ~FUSE_SPIEN & ~FUSE_BODLEVEL1 & ~FUSE_BODLEVEL0),
.high = (HFUSE_DEFAULT & ~FUSE_BOOTSZ1 & ~FUSE_BOOTSZ0 & ~FUSE_SPIEN & ~FUSE_EESAVE),
.extended = EFUSE_DEFAULT,
};
In this example:
.low sets the low fuse bits. LFUSE_DEFAULT is a predefined value for the default low fuse settings.
.high sets the high fuse bits. HFUSE_DEFAULT is a predefined value for the default high fuse settings.
.extended sets the extended fuse bits. EFUSE_DEFAULT is a predefined value for the default extended fuse settings.
Fuse Bits
Here are some common fuse bits and their meanings:
CKDIV8: Clock Divide by 8 Enable. When this fuse is programmed, the system clock is divided by 8.
SPIEN: Serial Programming and Data Downloading Enable. When this fuse is programmed, the SPI programming interface is enabled.
BODLEVELx: Brown-Out Detector (BOD) Voltage Level. These bits set the BOD trigger level.
BOOTSZx: Boot Loader Section Size. These bits determine the size of the boot loader section of the flash memory.
EESAVE: EEPROM Memory Preserve Enable. When this fuse is programmed, the EEPROM memory is preserved during chip erase.
Example of Setting the Low Fuse to 0xFF
To set the low fuse to 0xFF to use an external crystal oscillator, you can do the following:
c
Copy code
FUSES = {
.low = 0xFF,
.high = (HFUSE_DEFAULT & ~FUSE_BOOTSZ1 & ~FUSE_BOOTSZ0 & ~FUSE_SPIEN & ~FUSE_EESAVE),
.extended = EFUSE_DEFAULT,
};
Summary
Consult the Atmega328P datasheet for detailed information on fuse bits and their meanings.
Refer to the AVR Libc documentation for information on predefined fuse settings and the fuse structure.
Use AVRDUDE to read and write fuse settings and to get a list of available fuse bits and their meanings.
The example code shows how to define and modify fuse settings in Atmel AVR programming.
By combining information from these resources, you can gain a comprehensive understanding of fuse settings and how to modify them for your specific needs.