PDA

View Full Version : Eeprom Word Addressing



Simon Brodeur
- 13th September 2005, 14:48
I'm trying to write 16bit values from an accelerometer to a 256K external 12C EEPROM. To values should be turning around 1000. . I have some problem reading and/or writing the values.

I use the I2CREAD and I2CWRITE commands,with:
cbit = %1010000

When I read result, on the serial communicator, it looks of this:

1024
64367
1016
63290
1032
62986
...

I think the problem is the address variable
When I write word, in the form like:
I2CWRITE SDA,SCL,cbit,address,[word]

Will I have to increment address by 2 to write the next consecutive word?
Will it be the same for the I2CREAD?

I tried several manner of writing and reading and it didn't help me...

mister_e
- 13th September 2005, 14:55
that's true. An eeprom store a byte in each address location ( well those i know and use). So if you want to store a word... it will need to adresses. That's not a bug ;)

Simon Brodeur
- 13th September 2005, 15:02
Also, will any previous value at the same address be overwrited?

mister_e
- 13th September 2005, 15:08
As long as you increment/decrement your address by 2 you shouldn't overwrite any previous/next data.

Writing to the same adress ( let's say $06) will overwrite the previous value wich was @ $06 and $07

Acetronics2
- 13th September 2005, 17:35
Hi, Simon

I had the same problem with EEprom 16 bits storing ...

a simple way is to trucate values into Value.lowbyte and value.highbyte

for addressing, i.e use addresses for Highbytes as 2*n and for lowbytes as 2*n + 1 ...

and when reading you do the same.

there's no mix that way - just takes 2 I2CWRITE lines instead of 1 !!!

as address is defined as a Word ... the count for me is 65536 locations at max ...so, it could explain overwriting some values !!! for 256k you will probably have to add some extra block addressing.

in French .... would be easier !!! let's say this accelometer makes me think to something in the air ....

Alain

Simon Brodeur
- 14th September 2005, 00:23
I resolved some problem in my code, but something trouble me about the FOR...Next loop. My code is :

For address = 0 to last STEP 4
I2CREAD SDA,SCL,cbit,address,[xsend.Highbyte]
address = address + 1
I2CREAD SDA,SCL,cbit,address,[xsend.Lowbyte]
...
Next


My value in my EEPROM are like this (numbers are EEPROM locations) :

01 23 45 67 89
|xx|yy|xx|yy|xx|...

Normally, the output value of address should be : 0,4,8,12,16,...
But will the '' address = address + 1 '' line affect this output, giving result like this : 0,5,10,15,20,... ????????

This should be an easy question for you

mister_e
- 14th September 2005, 00:40
well yes no toaster hamburger. What about the whole variable definition or code?

Simon Brodeur
- 14th September 2005, 01:42
Here's my whole code... but it may be difficult to follow.

Check the subroutine LOAD, it is the problem I verified the writing with another program.

Simon Brodeur
- 14th September 2005, 02:23
I got it working...
I just simply read by word instead of read by byte...

Thanks you guys