M24C64 EEPROM Reading and Writing

Jon_

Member
Hi All,

I am having severe problems trying to get my head around how this chip is working, I know it shouldn't be that hard!!

Eventually I will have two temperature sensor which I wish to record the temp at certain time intervals. After which, I wish to retrieve the data, simply in the terminal window so i can copy that into excel to make graphs. However, to make it easy i am starting with two potentiometers (i don't have the temp sensors yet and i wanted to see how to use memory)

My problem is writing to the EEPROM, here is what I think is right (but obviously wrong as it doesn't work):

Code:
for b3 = 0 to 59
high 2
readadc 0,b0
readadc 1,b1

i2cslave %10100000, i2cfast ,i2cword
writei2c b3, (b0)
pause 10

b4 = b3 +1
writei2c b4, (b1)


pause 100
low 2
pause 100


next b3
So i want to record data in two different addresses. The high 2 and low 2 is merely an LED i have on the board to show me it is doing something.

Then to read it back I have:

Code:
for b3 = 0 to 59


i2cslave %10100000, i2cfast ,i2cword
readi2c b3, (b0)

b4 = b3 +1
readi2c b4, (b1)

sertxd("Temp1 = ", #b0,13,10)
sertxd("Temp2 = ", #b1,13,10)
pause 200

next b3
All i am getting back is that Temp1 is the same as Temp2, seeing as I am turning the pots round at different times, this certainly is not true!!



I think the problem is that i am not sure how to address which byte i want to write to, so everything is getting muddled in my head.

Any help would be very much appreciated!
 

Buzby

Senior Member
Hi JON_,

Your first problem is the For-Next loop in your listings.

'For 0 to 59' makes b3 count like this : 0, 1, 2, 3

So on the first loop, b3 = 0 and b4 = 1

You then write to eeprom locations 0 and 1

But on the second time round, b3 = 1 and b4 = 2

You then write to locations 1 and 2

See, you have written to location 1 twice !.

Put a 'step 2' in the 'for' lines, see the manual for details of the for/next syntax.

Cheers,

Buzby
 
Top