EEPROM

2,105 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,105
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
86
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

EEPROM

  1. 1. EEPROM Memory Storing, Reading, and Writing CS-280 Dr. Mark L. Hornick
  2. 2. Atmega32 Memory CS-280 Dr. Mark L. Hornick <ul><li>Address bus (16-bit in Atmega32) </li></ul><ul><ul><li>A unique 16-bit address references each memory byte. </li></ul></ul><ul><li>Data bus (8-bit) </li></ul><ul><li>Volatile – RAM (fast RW) </li></ul><ul><ul><li>SRAM (temp data store) </li></ul></ul><ul><ul><li>DRAM </li></ul></ul><ul><li>Nonvolatile – ROM (fast R – slow W) </li></ul><ul><ul><li>ROM </li></ul></ul><ul><ul><li>PROM </li></ul></ul><ul><ul><li>EPROM </li></ul></ul><ul><ul><li>EEPROM (permanent data store) </li></ul></ul><ul><ul><li>Flash ROM (program store) </li></ul></ul>
  3. 3. EEPROM is non-volatile memory <ul><li>Power does not have to be supplied to maintain values stored in EEPROM </li></ul><ul><li>EEPROM values are maintained when power is shut off </li></ul><ul><li>EEPROM is not affected if Program Memory is rewritten (new program loaded) </li></ul><ul><li>EEPROM can be written/erased at least 100,000 times </li></ul>CS-280 Dr. Mark L. Hornick
  4. 4. EEPROM Memory Addressing <ul><li>EEPROM is organized and accessed in bytes, as in SRAM </li></ul><ul><ul><li>There are 1024 bytes of EEPROM </li></ul></ul><ul><ul><li>Each byte has a unique 16-bit address </li></ul></ul><ul><ul><ul><li>But since there are only 1024 bytes of EEPROM, only 10 bits are used </li></ul></ul></ul><ul><ul><li>The first byte of EEPROM is at address 0x0000 </li></ul></ul><ul><ul><ul><li>As compared to SRAM, which starts at 0x0060 </li></ul></ul></ul>CS-280 Dr. Mark L. Hornick Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 0x0000 0x0001 0x0002 0x0003 0x0004 . . . 0x03FE 0x03FF Byte 1022 Byte 1023
  5. 5. Data can be stored in EEPROM via the .db directive <ul><li>.ESEG ; switch further directives to EEPROM segment </li></ul><ul><li>.ORG 0x0000 ; set addr for start of EEPROM </li></ul><ul><li>x1: .db 1,5 ; alloc 2 bytes in EEPROM with initial values of 1 and 5 </li></ul><ul><li>title: .db ‘c’,’e’,’2’,’8’,’0’, ‘0’,0 ; allocate 7 bytes in EEPROM </li></ul><ul><li>course: .db “CE-2800”, 0 ; allocate 8 bytes in EEPROM </li></ul><ul><li>Note assembler does NOT automatically insert a NULL char at the end of the string </li></ul><ul><li>The .db n,m,… (“define byte”) directive tells the assembler to allocate and store the bytes n,m… in EEPROM </li></ul><ul><ul><li>The initial values of the memory are specified </li></ul></ul>CS-280 Dr. Mark L. Hornick
  6. 6. The AVR Assembler creates a separate file (with the .EEP extension) containing EEPROM data <ul><li>You have to load the EEPROM values as a separate step in AVR Studio </li></ul><ul><li>Recall: The .HEX file contains opcodes for the program as well as Flash memory data </li></ul>CS-280 Dr. Mark L. Hornick
  7. 7. Downloading EEPROM data in AVR Studio <ul><li>From the Debug menu, select the “Up/Download Memory” command </li></ul><ul><ul><li>The debugger must be running for this command to become enabled </li></ul></ul>CS-280 Dr. Mark L. Hornick
  8. 8. Downloading EEPROM data using Atmon <ul><li>Recall: You use the WR V command to load the .HEX file containing the program and Flash memory data to Flash </li></ul><ul><li>Use the WRE V command to load the .EEP file containing the EEPROM data </li></ul>CS-280 Dr. Mark L. Hornick
  9. 9. Reading data from EEPROM <ul><li>There are no specific instructions to load (read) data from EEPROM </li></ul><ul><li>Instead, EEPROM is accessed as if it were an I/O Subsystem </li></ul><ul><ul><li>EEPROM is accessed via Special-purpose I/O Registers </li></ul></ul><ul><ul><ul><li>EECR – Control Register </li></ul></ul></ul><ul><ul><ul><li>EEARH – Address Register (high 2 bits) </li></ul></ul></ul><ul><ul><ul><li>EEARL – Address Register (low 8 bits) </li></ul></ul></ul><ul><ul><ul><li>EEDR - Data Register </li></ul></ul></ul>CS-280 Dr. Mark L. Hornick
  10. 10. Using EEPROM I/O Registers to read EEPROM data CS-280 Dr. Mark L. Hornick .ESEG ; put data in EEPROM values: .db 1,2,3,4,5 .CSEG CLR temp OUT EECR, temp ; clear EECR bits LDI ZL, LOW(values) ; low 8 bits of the address LDI ZH, HIGH(values) ; high 2 bits OUT EEARL, ZL ; write to EEPROM addr reg OUT EEARH, ZH SBI EECR, 0 ; set EERE=1 (read enable) IN temp, EEDR ; move data to temp register
  11. 11. Using EEPROM I/O Registers to write EEPROM data CS-280 Dr. Mark L. Hornick .ESEG ; reserve space in EEPROM values: .byte 5 .CSEG CLR temp OUT EECR, temp ; clear EECR bits LDI ZL, LOW(values) ; low 8 bits of the address LDI ZH, HIGH(values) ; high 2 bits OUT EEARL, ZL ; write to EEPROM addr reg OUT EEARH, ZH LDI temp, 0x0A OUT EEDR, temp ; value to be written SBI EECR, 2 ; master write enable ; note: EEMWE is cleared automatically after 4 clock cycles SBI EECR, 1 ; clr’d automatically after write EEWE is cleared automatically after the byte is actually written, but each EEPROM write takes several ms, so EEWE will remain set for some time

×