Monday, July 25, 2011

EEPROM


EEPROM (Electrically Erasable Programmable Read Only Memory) is one of the three memory types of AVRs (the other are the Flash memory and SRAM). EEPROM is able to retain its contents when there is no supply voltage. You can also change the EEPROM contents on runtime, so, EEPROM is useful to store information like calibration values, ID numbers, etc.
Most AVRs have some amount of EEPROM (the exceptions are ATtiny11 and ATtiny28). You must check the corresponding datasheet to know the exact amount of memory of your particular device.
To write in the EEPROM, you need to specify the data you want to write and the address at which you want to write this data. In order to prevent unintentional EEPROM writes (for instance, during power supply power up/down), a specific write procedure must be followed. The write process is not instantaneous, it takes between 2.5 to 4 ms. For this reason, your software must check if the EEPROM is ready to write a new byte (maybe a previous write opeartion is not finished yet).
The address of the byte you want to write is specified in the EEPROM Address Register (EEAR). If the AVR you are using has more than 256 bytes, the EEAR register is divided in the EEARH and EEARL registers. The EEPROM Data Register (EEDR) contains the data you want to store.
The EEPROM Control Register (EECR) is used to control the operation of the EEPROM. It has three bits : EEMWE, EEWE and EERE. The EERE (EEPROM Read Enable) bit is used to read the EEPROM and is discussed later. In order to issue an EEPROM write, you must first set the EEMWE (EEPROM Master Write Enable) bit, and then set the EEWE (EEPROM write enable) bit. If you don't set EEMWE first, setting EEWE will have no effect. The EEWE bit is also used to know if the EEPROM is ready to write a new byte. While the EEPROM is busy, EEWE is set to one, and is cleared by hardware when the EEPROM is ready. So, your program can poll this bit and wait until is cleared before writing the next byte.


settings for EEPROM is very nicely explained in the PDF of atmega16. I know laziness rocks so i have updated it here..

While writing a code for EEPROM settings, we require some basic knowledge of its registers.
So, first register is the address register. We know that EEPROM has 512 bytes of storage. Thus to access each bit, we have a separate address defined. now, 512 numbers can be associated with 9 binary bytes. But we have 8 bit registers. So to solve this problem, we have 2 address registers, EEARH & EEARL represnting high and low registers respectively.


As we can see, bits 9 to 15 are reserved. Hence they are of no use as of now.  The 9 bit address can be represented in bits 0 to 8, linearly between 0 to 511..as simple as that! Initially the value of EEAR is undefined.

this was all for addressing EEPROM. Now lets store some data..!!
EEDR is the eeprom data register. Now we have two operations in EEPROM, reading and writing data..so when EEDR is read, it contains data stored in the address specified by EEAR i.e. the address register. When EEPROM is written, values provided by us is stored in EEDR on the address specified by EEAR. So, we can see that data register and address registers go hand in hand.

Now, lets move on to the final register the control register! its bit tricky..but once you understand it, its a piece of cake..:)
7 to 4 bits are reserved!! so no need to care about them..!!
EERIE generates interrupt when it is set to 1. The EEPROM Ready interrupt generates a
constant interrupt when EEWE is cleared. Now, what is EEWE??? EEWE is EEPROM write enable. By setting this to 1, we set EEPROM in write mode. Previous data in EEDR would be replaced by new data provided. Now, coming to EEMWE,

The EEMWE bit determines whether setting EEWE to one causes the EEPROM to be
written. When EEMWE is set, setting EEWE within four clock cycles will write data to the
EEPROM at the selected address If EEMWE is zero, setting EEWE will have no effect.When EEMWE has been written to one by software, hardware clears the bit to zero after
four clock cycles.
EERE is simply read enable. Enable this bit while reading values in EEDR.


Few random points,
1. EEPROM reading and writing is slower than SRAM reading/writing process,
it waits 4 clock cycles for reading EEDR & 2 clock cycles for writing to EEDR.!!
2. Programming steps..
 a) Wait until EEWE becomes zero.
 b) Write a logical one to the EEMWE bit while writing a zero to EEWE in EECR.
 c) Within four clock cycles after setting EEMWE, write a logical one to EEWE.

with this, i think you can make a password recognization system very easily..and since we know about touchscreens, maybe try making a numpad on a resistive touchscreen...;)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.