ATmega128 (961723), страница 59
Текст из файла (страница 59)
Apply 4.5 - 5.5 V between VCC and GND, and wait at least 100 µs.2. Set RESET to “0” and toggle XTAL1 at least SIX times.3. Set the Prog_enable pins listed in Table 121 on page 293 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 External Crystal or External RC configuration is selected, it may not be possibleto apply qualified XTAL1 pulses.
In such cases, the following algorithm should befollowed:1. Set Prog_enable pins listed in Table on page 293 to “0000”.2. Apply 4.5 - 5.5V between VCC and GND simultaneously as 11.5 - 12.5V isapplied to RESET.3. Wait 100 µs.4. Re-program the fuses to ensure that External Clock is selected as clock source(CKSEL3:0 = 0b0000) If Lock bits are programmed, a Chip Erase commandmust be executed before changing the fuses.5. Exit Programming mode by power the device down or by bringing RESET pin to0b0.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 $FF, 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”294ATmega1282467M–AVR–11/04ATmega1281.
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.6. Wait until RDY/BSY goes high before loading a new command.Programming the FlashThe Flash is organized in pages, see Table 123 on page 293. 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 ($00 - $FF).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 ($00 - $FF).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 ($00 - $FF).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 137 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 136 on page 296.
Notethat if less than 8 bits are required to address words in the page (pagesize < 256), themost significant bit(s) in the address low byte are used to address the page when performing 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.2952467M–AVR–11/043. Set DATA = Address high byte ($00 - $FF).4. Give XTAL1 a positive pulse. This loads the address high byte.H. Program Page1. 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 137 for signal waveforms)I. Repeat B through H until the entire Flash is programmed or until all data has beenprogrammed.J. End Page Programming1. 1. 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 136. Addressing the Flash which is Organized in PagesPCMSBPROGRAMCOUNTERPAGEMSBPCPAGEPAGE ADDRESSWITHIN THE FLASHPROGRAM MEMORYPAGEPCWORDWORD ADDRESSWITHIN A PAGEPAGEINSTRUCTION WORDPCWORD[PAGEMSB:0]:000102PAGEENDNote:2961. PCPAGE and PCWORD are listed in Table 124 on page 293.ATmega1282467M–AVR–11/04ATmega128Figure 137. Programming the Flash WaveformsFDATAABCDE0x10ADDR. LOWDATA LOWDATA HIGHXXBCADDR.
LOW DATA LOWDEDATA HIGHXXGADDR. HIGHHXXXA1XA0BS1XTAL1WRRDY/BSYRESET +12VOEPAGELBS2Note:Programming the EEPROM“XX” is don’t care. The letters refer to the programming description above.The EEPROM is organized in pages, see Table 124 on page 293. 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 295 for details onCommand, Address and Data loading):1. A: Load Command “0001 0001”.2. G: Load Address High Byte ($00 - $FF).3.
B: Load Address Low Byte ($00 - $FF).4. C: Load Data ($00 - $FF).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 138 for signal waveforms.)2972467M–AVR–11/04Figure 138.
Programming the EEPROM WaveformsKADATA0x11GBADDR. HIGH ADDR. LOWCEBCDATAXXADDR. LOWDATAELXXXA1XA0BS1XTAL1WRRDY/BSYRESET +12VOEPAGELBS2Reading the FlashThe algorithm for reading the Flash memory is as follows (refer to “Programming theFlash” on page 295 for details on Command and Address loading):1. A: Load Command “0000 0010”.2. G: Load Address High Byte ($00 - $FF).3. B: Load Address Low Byte ($00 - $FF).4. Set OE to “0”, and BS1 to “0”. The Flash word low byte can now be read at DATA.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 295 for details on Command and Address loading):1. A: Load Command “0000 0011”.2.
G: Load Address High Byte ($00 - $FF).3. B: Load Address Low Byte ($00 - $FF).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 295 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. Set BS1 to “0” and BS2 to “0”.4.
Give WR a negative pulse and wait for RDY/BSY to go high.298ATmega1282467M–AVR–11/04ATmega128Programming the Fuse HighBitsThe algorithm for programming the Fuse High bits is as follows (refer to “Programmingthe Flash” on page 295 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.
Set BS1 to “1” and BS2 to “0”. This selects high data byte.4. Give WR a negative pulse and wait for RDY/BSY to go high.5. Set BS1 to “0”. This selects low data byte.Programming the ExtendedFuse BitsThe algorithm for programming the Extended Fuse bits is as follows (refer to “Programming the Flash” on page 295 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. Set BS2 to “1” and BS1 to “0”. This selects extended data byte.4. Give WR a negative pulse and wait for RDY/BSY to go high.5. Set BS2 to “0”. This selects low data byte.Figure 139. Programming the FusesWrite Fuse Low byteDATAAC$40DATAXXWrite Fuse high byteAC$40DATAXXWrite Extended Fuse byteAC$40DATAXXXA1XA0BS1BS2XTAL1WRRDY/BSYRESET +12VOEPAGELProgramming the Lock BitsThe algorithm for programming the Lock bits is as follows (refer to “Programming theFlash” on page 295 for details on Command and Data loading):1. A: Load Command “0010 0000”.2. C: Load Data Low Byte.
Bit n = “0” programs the Lock bit.3. Give WR a negative pulse and wait for RDY/BSY to go high.The Lock bits can only be cleared by executing Chip Erase.Reading the Fuse and LockBitsThe algorithm for reading the Fuse and Lock bits is as follows (refer to “Programmingthe Flash” on page 295 for details on Command loading):1. A: Load Command “0000 0100”.2. Set OE to “0”, BS2 to “0”, and BS1 to “0”. The status of the Fuse Low bits cannow be read at DATA (“0” means programmed).3. Set OE to “0”, BS2 to “1”, and BS1 to “1”. The status of the Fuse High bits cannow be read at DATA (“0” means programmed).2992467M–AVR–11/044.
Set OE to “0”, BS2 to “1”, and BS1 to “0”. The status of the Extended Fuse bitscan now be read at DATA (“0” means programmed).5. Set OE to “0”, BS2 to “0”, and BS1 to “1”. The status of the Lock bits can now beread at DATA (“0” means programmed).6. Set OE to “1”.Figure 140.