How to write to upper 32K of a AT24C512 eeprom??
radialrandy
Posts: 78
I'm trying to find the simplest way to write data to addresses in the upper 32K of the 62K eeprom. Cant I not directly write to the upper addresses because they are not part of main memory. FYI I really only know how to write in Spin. What I'm trying to do is datalog word sized data back to back in the memory and later read that data in word size. So lets say I want to start saveing word sized data at address $8000 and the next word at $8002 then next at $8004 and so on.
thanks
Randy
thanks
Randy
Comments
Look at the bottom of the post for "Similar Threads". Should be what you need.
Use:
To write a word sized variable to EEPROM. Use addresses $8000 or more (up to $FFFF) for upper EEPROM.
Use the ToRam method to take a value from EEPROM.
There is an EEPROM datalogging link in the PEK sticky.
Let me know if you need any clarification.
I've looked at the Basic_I2C_Driver but I'm confused on how to use it. Is there any demo example on how to use it?
Thanks
Randy
To write a word $1234 to location $8004/5 if you declare the object as I2C:
I2C.WriteWord( I2C#BootPin, I2C#EEPROM, $8004, $1234)
repeat while I2C.WriteWait( I2C#BootPin, I2C#EEPROM, $8004)
To read a word from location $8004/5:
theWordValue := I2C.ReadWord( I2C#BootPin, I2C#EEPROM, $8004)
Remember that the parameters to these methods (like $8004 and $1234) can be any expression, not just the constants shown.
The "repeat while" loop will hang if there's no EEPROM at the specified address. See the WriteIt example in the object's comments for
additional code that implements a timeout for this.
Would I write it like below? And what would go in devSel ?
OBJ
i2c : "Basic_I2C_Driver.spin"
Main
i2c.WriteWord(28, devSel, $8000, 1234)
i2c.WriteWait(28, devSel, addrReg)
devSel is device select.
He has:
Up in the constant section.
So you'd use "I2C#EEPROM" as your devSel parameter. Assuming you called the I2C object "I2C".
The "#" lets you use constants in a child object.
I hope Mike and Randy don't mind my interuption. I'm just excited to know the answer to this one.
Where does $A0 come from?
The least significant bit may be 1 or 0 in some I2C transactions: $A0 or $A1.
You can have multiple I2C devices on one I2C bus. The protocol uses addresses in order to identify the device you want to communicate with. You can have multiple EEPROMs on the same bus if you tie an address pin high (on the second EEPROM chip) in order to asign it a different address.
Some 1024K chips use a different address to select a different portion of the EEPROM. With these chips one of the normal address pins is "not connected" internally. I believe the "not connected" pin can varry depending on the brand of EEPROM so you want to make sure and read the datasheet.
I believe the "1" or "0" jazzed just mentioned are added by the driver so you don't need to worry about that part.
Randy,
I was just reading a bit more of Mike's driver. He explains about adressing in different EEPROM chips in the comments. I also noticed this in the comments:
So it looks like you normally wouldn't need to use the Initialize method.
My guess is the Start method should be use. I doubt it would hurt anything to use it.
I think the Stop method is used by other methods and I don't think you need to use it directly.
If you're using other I2C drivers in the the same project you'll want to set all the pins used to inputs and set them to their "low" state so other cogs can use the pins. (I had this problem once when using a different driver to read a real time clock.)
Edit: I hope Mike (or others) will correct me if I am incorrect about any of this.
Any Idea why this is not working?
thanks
I'd think you'd want to follow Mike's examples and only change the EEPROM address and the value to write to the address.
tried this and still no worky!
The first parameter has to be the pin number of the first of two I/O pins as described in the comments in the object. The constant "BootPin" is there to simplify things when you're using the Propeller's boot EEPROM.
The second parameter has to be the device's select code which is $A0 for most EEPROMs. The constant "EEPROM" is there to simplify things when you're using a common serial EEPROM.
The Start and Stop routines are PUB methods instead of PRI because they might be useful for someone using a non-EEPROM device. They're otherwise used internally. The Initialize routine is there for the reasons described in the comments.
Does your code output anything? If so what?
For testing make your write delay longer and add a debug line to see what values are being written to the EEPROM.
I simplified this to where all it does is save 100 to address $8100 then reads it to the terminal.
It does nothing. actually the program stops at the "repeat while" line. If I remove just the repeat while and leave the rest I do get a reading on the terminal .it outputs 65535.
Mike thanks for helping but I am trying. I'm just missing something.
Can the A0 for the eeprom address not be right for some reason. Cause the program hangs up on the repeat loop. A0,A1,A2 on the eeprom chip are grounded.
test1 := i2c.ReadWord(i2c#BootPin, i2c#EEPROM, $8100)
FD.str(String(13,"rpm= "))
FD.dec(test1)
and changed the $8100 to other address just to see if I could read anything. All I ever get is 65535 on the terminal. I dont know anything else to try. I just want to write and read data to addresses.
Sorry but I use the object Propeller Eeprom (I think that's what it's called) when I store stuff to EEPROM. The Propeller Education Kit sticky on the main Propeller forum page has a link to an EEPROM data logging lab. That's the code I used when I was first learning to use the Propeller. It worked so I haven't bothered to learn how to write to the EEPROM a different way.
The line of code I wrote in post #3 will write a word to EEPROM.
The @myWord part assumes you have a word variable declared named "myWord". The eepromAddress would be a value such as $8100.
I actually use that object for some of my data saves. But I have not got it to work to save to specific addresses in the upper 32K of the 64K eeprom.
Works good for saving named varibles.
The attached program will tell you if your EEPROM is 32K or 64K.
When I run the program on my Demo board(which has 32K EEPROM) I get this.
When I run it on a board with 64K or EEPROM I get this output.
The program uses a baud of 57,600. It gives you three seconds to open a terminal window before it starts sending information to the terminal window. You can either load into RAM(F10) or EEPROM(F11). (Of course if you load it to RAM, it will only run once.)
This should let you know if your EEPROM is 32K or 64K.
I found the problem. I'm using the propellor eeprom object and the i2c object in my program. and when this runs "eeprom.VarRestore(@setpoint, @control[1500])" then the i2c stuff does not work. Can I not have 2 different eeprom controlling objects in my program? Any input on why it does not work? When I remove the line "eeprom.VarRestore(@setpoint, @control[1500])" I can read and write with the i2c perfectly.
You can also use Basic_I2C_Driver to do the same sort of thing as VarRestore. Just write the data (valueToSave) to the corresponding location for the variable (globalVariable) in EEPROM like:
I2C.WriteWord( I2C#BootPin, I2C#EEPROM, @globalVariable, valueToSave)
repeat while I2C.WriteWait( I2C#BootPin, I2C#EEPROM, @globalVariable)
When the program restarts, globalVariable will be initialized to the value valueToSave. Obviously, use WriteByte or WriteLong if that's appropriate for the variable.
thanks