ATmega8 (961722), страница 46
Текст из файла (страница 46)
Pin Values used to Enter Programming ModePinSymbolValuePAGELProg_enable[3]0XA1Prog_enable[2]0XA0Prog_enable[1]0BS1Prog_enable[0]0Table 93. XA1 and XA0 CodingXA1XA0Action when XTAL1 is Pulsed00Load Flash or EEPROM Address (High or low address byte determined by BS1)01Load Data (High or Low data byte for Flash determined by BS1)10Load Command11No Action, IdleTable 94.
Command Byte Bit CodingCommand Byte224Command Executed1000 0000Chip Erase0100 0000Write Fuse Bits0010 0000Write Lock Bits0001 0000Write Flash0001 0001Write EEPROM0000 1000Read Signature Bytes and Calibration byte0000 0100Read Fuse and Lock Bits0000 0010Read Flash0000 0011Read EEPROMATmega8(L)2486O–AVR–10/04ATmega8(L)Parallel ProgrammingEnter Programming ModeThe following algorithm puts the device in Parallel Programming mode:1. Apply 4.5 - 5.5V between VCC and GND, and wait at least 100 µs.2.
Set RESET to “0” and toggle XTAL1 at least 6 times3. Set the Prog_enable pins listed in Table 92 on page 224 to “0000” and wait atleast 100 ns.4. Apply 11.5 - 12.5V to RESET. Any activity on Prog_enable pins within 100 nsafter +12V has been applied to RESET, will cause the device to fail entering Programming mode.Note, if the RESET pin is disabled by programming the RSTDISBL Fuse, it may not bepossible to follow the proposed algorithm above.
The same may apply when ExternalCrystal or External RC configuration is selected because it is not possible to apply qualified XTAL1 pulses. In such cases, the following algorithm should be followed:1. Set Prog_enable pins listed in Table 92 on page 224 to “0000”.2. Apply 4.5 - 5.5V between VCC and GND simultaneously as 11.5 - 12.5V isapplied to RESET.3. Wait 100 ns.4. Re-program the fuses to ensure that External Clock is selected as clock source(CKSEL3:0 = 0’b0000) and RESET pin is activated (RSTDISBL unprogrammed).If Lock Bits are programmed, a chip erase command must be executed beforechanging the fuses.5. Exit Programming mode by power the device down or by bringing RESET pin to0’b0.6. Entering Programming mode with the original algorithm, as described above.Considerations for EfficientProgrammingChip EraseThe loaded command and address are retained in the device during programming.
Forefficient programming, the following should be considered.•The command needs only be loaded once when writing or reading multiple memorylocations.•Skip writing the data value 0xFF, that is the contents of the entire EEPROM (unlessthe EESAVE Fuse is programmed) and Flash after a Chip Erase.•Address High byte needs only be loaded before programming or reading a new 256word window in Flash or 256 byte EEPROM. This consideration also applies toSignature bytes reading.The Chip Erase will erase the Flash and EEPROM(1) memories plus Lock Bits.
The LockBits are not reset until the Program memory has been completely erased. The Fuse Bitsare not changed. A Chip Erase must be performed before the Flash and/or theEEPROM are reprogrammed.Note:1. The EEPRPOM memory is preserved during chip erase if the EESAVE Fuse isprogrammed.Load Command “Chip Erase”1. Set XA1, XA0 to “10”.
This enables command loading.2. Set BS1 to “0”.3. Set DATA to “1000 0000”. This is the command for Chip Erase.4. Give XTAL1 a positive pulse. This loads the command.5. Give WR a negative pulse. This starts the Chip Erase. RDY/BSY goes low.2252486O–AVR–10/046. Wait until RDY/BSY goes high before loading a new command.Programming the FlashThe Flash is organized in pages, see Table 89 on page 222. When programming theFlash, the program data is latched into a page buffer.
This allows one page of programdata to be programmed simultaneously. The following procedure describes how to program the entire Flash memory:A. Load Command “Write Flash”1. Set XA1, XA0 to “10”. This enables command loading.2. Set BS1 to ”0”.3. Set DATA to “0001 0000”. This is the command for Write Flash.4.
Give XTAL1 a positive pulse. This loads the command.B. Load Address Low byte1. Set XA1, XA0 to “00”. This enables address loading.2. Set BS1 to “0”. This selects low address.3. Set DATA = Address Low byte (0x00 - 0xFF).4. Give XTAL1 a positive pulse. This loads the address Low byte.C. Load Data Low byte1. Set XA1, XA0 to “01”. This enables data loading.2. Set DATA = Data Low byte (0x00 - 0xFF).3. Give XTAL1 a positive pulse.
This loads the data byte.D. Load Data High byte1. Set BS1 to “1”. This selects high data byte.2. Set XA1, XA0 to “01”. This enables data loading.3. Set DATA = Data High byte (0x00 - 0xFF).4. Give XTAL1 a positive pulse. This loads the data byte.E. Latch Data1. Set BS1 to “1”. This selects high data byte.2. Give PAGEL a positive pulse. This latches the data bytes. (See Figure 106 forsignal waveforms)F.
Repeat B through E until the entire buffer is filled or until all data within the page isloaded.While the lower bits in the address are mapped to words within the page, the higher bitsaddress the pages within the FLASH. This is illustrated in Figure 105 on page 227. Notethat if less than eight bits are required to address words in the page (pagesize < 256),the most significant bit(s) in the address Low byte are used to address the page whenperforming a page write.G.
Load Address High byte1. Set XA1, XA0 to “00”. This enables address loading.2. Set BS1 to “1”. This selects high address.3. Set DATA = Address High byte (0x00 - 0xFF).4. Give XTAL1 a positive pulse. This loads the address High byte.H. Program Page226ATmega8(L)2486O–AVR–10/04ATmega8(L)1. Set BS1 = “0”2. Give WR a negative pulse. This starts programming of the entire page of data.RDY/BSY goes low.3. Wait until RDY/BSY goes high. (See Figure 106 for signal waveforms)I. Repeat B through H until the entire Flash is programmed or until all data has beenprogrammed.J. End Page Programming1. Set XA1, XA0 to “10”. This enables command loading.2. Set DATA to “0000 0000”.
This is the command for No Operation.3. Give XTAL1 a positive pulse. This loads the command, and the internal write signals are reset.Figure 105. Addressing the Flash which is Organized in Pages(1)PCMSBPROGRAMCOUNTERPAGEMSBPCPAGEPAGE ADDRESSWITHIN THE FLASHPROGRAM MEMORYPAGEPCWORDWORD ADDRESSWITHIN A PAGEPAGEINSTRUCTION WORDPCWORD[PAGEMSB:0]:000102PAGEENDNote:1. PCPAGE and PCWORD are listed in Table 89 on page 222.2272486O–AVR–10/04Figure 106.
Programming the Flash Waveforms(1)FADATA0x10BADDR. LOWCDATA LOWDEBCDEDATA HIGHXXADDR. LOWDATA LOWDATA HIGHXXGADDR. HIGHHXXXA1XA0BS1XTAL1WRRDY/BSYRESET +12VOEPAGELBS2Note:Programming the EEPROM1. “XX” is don’t care. The letters refer to the programming description above.The EEPROM is organized in pages, see Table 90 on page 222. When programmingthe EEPROM, the program data is latched into a page buffer. This allows one page ofdata to be programmed simultaneously. The programming algorithm for the EEPROMData memory is as follows (refer to “Programming the Flash” on page 226 for details onCommand, Address and Data loading):1. A: Load Command “0001 0001”.2.
G: Load Address High byte (0x00 - 0xFF).3. B: Load Address Low byte (0x00 - 0xFF).4. C: Load Data (0x00 - 0xFF).5. E: Latch data (give PAGEL a positive pulse).K: Repeat 3 through 5 until the entire buffer is filled.L: Program EEPROM page.1. Set BS1 to “0”.2. Give WR a negative pulse. This starts programming of the EEPROM page.RDY/BSY goes low.3. Wait until to RDY/BSY goes high before programming the next page.(See Figure 107 for signal waveforms).228ATmega8(L)2486O–AVR–10/04ATmega8(L)Figure 107.
Programming the EEPROM WaveformsKADATA0x11GADDR. HIGHBCADDR. LOWDATAEXXBADDR. LOWCDATAELXXXA1XA0BS1XTAL1WRRDY/BSYRESET +12VOEPAGELBS2Reading the FlashThe algorithm for reading the Flash memory is as follows (refer to “Programming theFlash” on page 226 for details on Command and Address loading):1. A: Load Command “0000 0010”.2.
G: Load Address High byte (0x00 - 0xFF).3. B: Load Address Low byte (0x00 - 0xFF).4. Set OE to “0”, and BS1 to “0”. The Flash word Low byte can now be read atDATA.5. Set BS1 to “1”. The Flash word High byte can now be read at DATA.6. Set OE to “1”.Reading the EEPROMThe algorithm for reading the EEPROM memory is as follows (refer to “Programming theFlash” on page 226 for details on Command and Address loading):1. A: Load Command “0000 0011”.2.
G: Load Address High byte (0x00 - 0xFF).3. B: Load Address Low byte (0x00 - 0xFF).4. Set OE to “0”, and BS1 to “0”. The EEPROM Data byte can now be read atDATA.5. Set OE to “1”.Programming the Fuse LowBitsThe algorithm for programming the Fuse Low bits is as follows (refer to “Programmingthe Flash” on page 226 for details on Command and Data loading):1. A: Load Command “0100 0000”.2. C: Load Data Low byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit.3.