Shop OBEX P1 Docs P2 Docs Learn Events
Reading & Writing LONGS to the EEPROM via i2c — Parallax Forums

Reading & Writing LONGS to the EEPROM via i2c

DavidMDavidM Posts: 626
edited 2008-07-02 11:13 in Propeller 1
Hi,

I need to save and load LONGS ( from a long array) or just plain LONGS to the eeprom ( Microchip 24LC256) via i2c
eg
VAR
     LONG MyVariableArray[noparse][[/noparse]7]



I understand the eeprom holds its data as 8bit values ( bytes)

I want to use the i2cObject to do this. ( as I have used this object for my LCD and I am familiar with it)

I know the device ID is $A0
I want to start the variables from eeprom location $7000 onwards ( I believe this is safe to do)



So far..
I have two functions to read and write 1 byte of data ( 8bits) to and from the eeprom..

PUB LoadVariable ( AddressOffset ) : Data
       Data:=i2c.ReadLocation( $A0, $7000+AddressOffset, 16, 8)
       RETURN Data
& 

PUB SaveVariable ( AddressOffset, Data )
       i2c.WriteLocation ( $A0, $7000 + AddressOffset, Data, 16, 8 )




I also know that I have to initialize the i2c
i2c.Init(29,28,False)




PROBLEM 1)
For some reason I cannot save or load data >8 for the VariableOffset?

PROBLEM 2)
If I want to add 4 bytes together to make up a LONG once I have read the bytes from the eeprom I cannot seem to SHIFT the BITS, only the first "BYTE" is recognised
i.e
LONG[noparse][[/noparse]@MyVaribaleArray][noparse][[/noparse]0] := LoadVariable(0) + LoadVariable(1)<<8 + LoadVariable(2)<<16 + LoadVariable(3)<<24




Any Ideas ?

Thanks


Dave M

Comments

  • JavalinJavalin Posts: 892
    edited 2008-07-02 11:13
    Hiya

    It might be easier to use the i2cObject v2 or Mike Greens excellent basic_i2c_object. Mike has written specific byte,word,long and page read/write functions....

    James
Sign In or Register to comment.