Correctly configure the AVR ATmega128 fuse bits

Publisher:Xingfu6666Latest update time:2016-10-18 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I have been working on the AVR ATmega128 program these days to display the most basic functions. However, because it uses the PORTG port, which is placed in the internal SRAM of the ATmega128 for compatibility with the ATmega103, it is not accessible by default when leaving the factory.

Because of this problem, I was delayed for a few days. Now I see the following article, and finally "the light is shining". Reposted here for the record!

 

        The configuration of AVR fuse bits is a relatively delicate task, and users often overlook its importance or find it difficult to master. The following are some key points and related matters that need to be paid attention to when configuring the AVR fuse bits.

 

       (1) In the AVR device manual, the fuse bits are described as programmed and unprogrammed.

(Unprogrammed) defines the state of the fuse bit. "Unprogrammed" means the fuse state is "1" (disabled); "Programmed" means the fuse state is "0" (allowed). Therefore, the process of configuring the fuse bit is actually "configuring the fuse bit to be unprogrammed state "1" or programmed state "0".

 
      (2) When using programming tool software that allows you to determine the fuse bit status value by checking the box, please first read the software instructions carefully to understand whether "√" means setting the fuse bit status to "0" or "1".

 
      (3) When using the programming download program in CVAVR, special attention should be paid. Since the initial state of most fuse bits is defined as "1" when the CVAVR programming download interface is initially opened, do not use the "all" option in its programming menu options. At this time, the "all" option will configure the fuse bits of the chip according to the initial state definition of the fuse bits, but in fact it is often not the configuration result required by the user. If you want to use the "all" option, you should first use "read->fuse bits" to read the actual state of the fuse bits in the chip, and then use the "all" option.


      (4) Before using a new AVR chip, you should first check the configuration of its fuse bits, then configure the fuse bits according to actual needs, and record the status of each fuse bit for filing.


      (5) After the AVR chip is encrypted, only the data in the internal Flash and E2PROM of the chip cannot be read. The status of the fuse bits can still be read, but the configuration cannot be modified. The chip erase command clears the data in the Flash and E2PROM, and at the same time configures the status of the two lock bits to "11", which is in an unlocked state. However, the chip erase command does not change the status of other fuse bits.


      (6) The correct operation procedure is: when the chip is unlocked, download the running code and data, configure the relevant fuse bits, and finally configure the chip lock bits. After the chip is locked, if the fuse bits are found to be incorrectly configured, the chip erase command must be used to clear the data in the chip and unlock it. Then re-download the running code and data, modify the configuration-related fuse bits, and finally configure the chip lock bits again.


       (7) When using ISP serial download programming, the SPIEN fuse bit should be configured to "0". The default state of the SPIEN bit when the chip leaves the factory is "0", indicating that ISP serial download data is allowed. Only when this bit is in the programmed state "0" can ISP download be performed through the SPI port of the AVR. If this bit is configured as unprogrammed "1", ISP serial download data is immediately prohibited. At this time, the SPIEN state can only be reset to "0" through parallel mode or JTAG programming to open ISP. Under normal circumstances, the SPIEN state should be kept at "0". Allowing ISP programming will not affect the I/O function of its pins, as long as the ISP interface and the devices connected in parallel are isolated when designing the hardware circuit, such as using series resistors or circuit breaker jumpers.


      (8) When your system does not use the JTAG interface for download programming or real-time online simulation debugging, and the pins of the JTAG interface need to be used as I/O ports, the fuse bit JTAGEN must be set to "1". The JTAGEN state of the chip is "0" by default when it leaves the factory, indicating that the JTAG interface is allowed and the external pins of JTAG cannot be used as I/O ports. When the JTAGEN state is set to "1", the JTAG interface is immediately disabled. At this time, JTAG can only be reset to "0" and JTAG can only be opened through parallel mode or ISP programming.


      (9) In general, do not set the fuse to define the RESET pin as I/O (such as setting the ATmega8 fuse RSTDISBL to "0"). This will cause the ISP download programming to be unable to proceed, because before entering the ISP mode programming, the RESET pin needs to be pulled low to put the chip into the reset state first.


      (10) When using an AVR chip with an internal RC oscillator, pay special attention to the configuration of the fuse bit CKSEL. Generally, the default state of the CKSEL bit when the chip leaves the factory is to use the internal 1MHz RC oscillator as the system clock source. If you use an external oscillator as the system clock source, do not forget to correctly configure the CKSEL fuse bit first, otherwise the timing of your entire system will be problematic. When your design does not use an external oscillator (or a specific oscillation source) as the system clock source, do not misoperate or mistakenly configure the CKSEL fuse bit to use an external oscillator (or other different types of oscillation sources). Once this happens, the chip cannot be operated using the ISP programming method (because the ISP method requires the chip's system clock to work and generate timing control signals), and the chip looks "broken". At this time, the only way to save it is to remove the chip and use the parallel programming method, or use the JTAG method (if JTAG is allowed and there is a JTAG interface on the target board). Another way to solve the problem is to try to temporarily add different types of oscillation clock signals to the crystal pins of the chip. Once the ISP can operate the chip, immediately configure CKSEL to use the internal 1MHz RC oscillator as the system clock source, and then reconfigure CKSEL correctly according to the actual situation.


      (11) When using an AVR chip that supports IAP, if you do not use the BOOTLOADER function, be careful not to set the fuse bit BOOTRST to "0", as it will cause the chip to not start executing the program from 0x0000 of the Flash when it is powered on. The default state of the BOOTRST bit is "1" when the chip leaves the factory.


 Configuration of important fuses in ATmega128 
   
      (1) Fuse M103C. The configuration of M103C will set whether ATmega128 works in ATmega103 compatible mode or in ATmega128 native mode. When ATmega128 leaves the factory, the default state of M103C is "0", that is, it works in ATmega103 compatible mode by default. When the user system design makes the chip work in ATmega128 mode, the state of M103C should be configured to "1" first.

 
      (2) CLKSEL0..3. CLKSEL0, CLKSEL1, CLKSEL2, and CLKSEL3 are used to select the clock source of the system. There are five different types of clock sources to choose from (each type has finer divisions). The default settings of the chip when it leaves the factory are "0001" for CLKSEL3..0 and "10" for SUT1..0, respectively. That is, the internal 1MHz RC oscillator is used with the longest startup delay. This ensures that the initial ISP download can be performed regardless of whether the external oscillation circuit is working. The rewriting of the CLKSEL3..0 fuse bit needs to be done very carefully, because once the rewriting is wrong, the chip will not be able to start.


      (3) JTAGEN. If the JTAG interface is not used, the status of JTAGEN should be set to "1", that is, JTAG is disabled and the JTAG pins are used as I/O ports. 


       (4) SPIEN. SPI mode downloading of data and programs is allowed, and the default state is "0". Generally, its state is retained.


       (5) WDTON. The watchdog timer is always on. WDTON defaults to "1", which means that the watchdog timer is always disabled. If this bit is set to "0", the watchdog timer will always be on and cannot be controlled by the internal program. This is designed to prevent unknown code from turning off the watchdog timer by writing to the register when the program runs away (although turning off the watchdog timer requires a special method, it ensures higher reliability).


       (6) EESAVE. Whether to retain the contents in the E2PROM when executing the erase command. The default state is "1", indicating that the contents in the E2PROM are erased together with the contents in the Flash. If this bit is set to "0", the erase command before downloading the program will only be effective for the FLASH code area, but not for the E2PROM area. This is very useful when you want to retain the data in the E2PROM when updating the system program.


       (7) BOOTRST. Determines the address of the first instruction executed when the chip is powered on. The default state is "1", indicating that execution starts from 0x0000 when starting. If BOOTRST is set to "0", the program will be executed from the starting address of the BOOTLOADER area when starting. The size of the BOOTLOADER area is determined by BOOTSZ1 and BOOTSZ0, so its first address also changes accordingly.


       (8) BOOTSZ1 and BOOTSZ0: These two bits determine the size of the BOOTLOADER area and its starting address. The default state is "00", which means that the BOOTLOADER area is 4096 words and the starting address is 0xF000.


       (9) It is recommended that users use the ISP method to configure the fuse bits. The configuration tool uses BASCOM-AVR (online download trial version, which has no restrictions on ISP downloads) and a download cable compatible with STK200/STK300.



Note: Different AVRs have different fuses, so you must carefully check the chip manual before use. 

Keywords:AVR Reference address:Correctly configure the AVR ATmega128 fuse bits

Previous article:Analysis of digital power supply circuit designed by foreigners using AVR
Next article:Implementation of AVR single button state machine

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号