Hey guys!

I just played around with the Arduino EEPROM to learn how it works.

``````/*
Name:		EEPROMTest.ino
Created:	18.07.2015 09:44:58
Author:	Falke
*/
#include <EEPROM.h>

// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);

byte value = 0xFF;
EEPROM.write(3000, value);
}

// the loop function runs over and over again until power down or reset
void loop() {

}
``````

Well I know that this EEPROM has a size of 1024 Bytes. Thats why I wonder why I can write on adresses exceeding these 1024 like 3000 I used in the code above. I thought the adresses where static and therefore I had to go from 0 to 1023 to use the full memory range of bytes on that EEPROM. But since I can an arbitrary number as adress I’m kinda lost here.

Does anybody see my issue here and mybe can explain me what I’m thinking of wrong?

greets Charlie

Falke88:
Well I know that this EEPROM has a size of 1024 Bytes. Thats why I wonder why I can write on adresses exceeding these 1024 like 3000 I used in the code above. I thought the adresses where static and therefore I had to go from 0 to 1023 to use the full memory range of bytes on that EEPROM. But since I can an arbitrary number as adress I’m kinda lost here.

Does anybody see my issue here and mybe can explain me what I’m thinking of wrong?

A 1024 byte EEPROM is to be addressed with 10 bits as 210=1024 addresses (0…1023)

If you are trying to adress 12 bits like that:

``````101110111000 = decimal 3000
``````

the EEPROM is actually written at the 10 bit address

``````1110111000 = decimal 952
``````

So while you are thinking you are writing at decimal address 3000 you are actually writing at decimal address 952, which is the same 10-bit pattern of 10 bits you can address.

As Jurs said, the AVR EEPROMs only use the bits needed to make up the address range.

To ensure you do not exceed the last address and start wrapping back to zero (on devices with less or more space that what you test), you can use EEPROM.length(); (Added to EEPROM lib from IDE 1.6.2).

alright got it! Thank you guys