i2c EEProm not saving data
Hi friends. I just started learning the Propeller platform a few weeks ago. While I already have made the Propeller do alot of fun stuff, I need help solving a stange problem. It seems I cannot write to an EEPROM.
I am using the Gadget Gangster USB platform to do this test and the object I am tring to use is the I2C_ROMEngine.
I wanted to confirm I understood how to use this object so I wrote some simple code to store a value into a EEProm register and then retrive it.
I upload the code into EEPROM and run it
The terminal screen successfuly displays the value >>>123<<<, obviously storing the value into the EEProm then recalling it.
To double test this, I then upload the following code into RAM (not the EEPROM). Its the same code as above but I comment out the line that saves data to the EEPROM.
At this point I am only interested in reading EEPROM data that was put in the EEPROM using the code above.
What am I doing wrong?
I am using the Gadget Gangster USB platform to do this test and the object I am tring to use is the I2C_ROMEngine.
I wanted to confirm I understood how to use this object so I wrote some simple code to store a value into a EEProm register and then retrive it.
I upload the code into EEPROM and run it
CON
_clkmode = rcfast
OBJ
RomEngine: "I2C_ROMEngine"
term : "Parallax Serial Terminal"
PUB Main
term.Start(9600)
RomEngine.ROMEngineStart (29, 28, 0) '(dataPinNumber, clockPinNumber, lockNumberToUse)
term.str(string("hello",13))
waitcnt (10000000+cnt)
term.str(string("writing 123 to eeprom memory location 7080",13))
RomEngine.writeByte(7080, string("123")) '(EEPROMaddress, value)
waitcnt (10000000+cnt)
term.str(string("pausing just incase", 13))
waitcnt (10000000+cnt)
term.str (string("reading from memory location 7080", 13))
term.str (string(">>>"))
term.str (RomEngine.readByte(7080))
term.str (string("<<<"))
The terminal screen successfuly displays the value >>>123<<<, obviously storing the value into the EEProm then recalling it.
To double test this, I then upload the following code into RAM (not the EEPROM). Its the same code as above but I comment out the line that saves data to the EEPROM.
At this point I am only interested in reading EEPROM data that was put in the EEPROM using the code above.
CON
_clkmode = rcfast
OBJ
RomEngine: "I2C_ROMEngine"
term : "Parallax Serial Terminal"
PUB Main
term.Start(9600)
RomEngine.ROMEngineStart (29, 28, 0) '(dataPinNumber, clockPinNumber, lockNumberToUse)
term.str(string("hello",13))
waitcnt (10000000+cnt))
'term.str(string("writing 123 to eeprom memory location 7080",13))
'RomEngine.writeByte(7080, string("123")) '(EEPROMaddress, value)
waitcnt (10000000+cnt)
term.str(string("pausing just incase", 13))
waitcnt (10000000+cnt)
term.str (string("reading from memory location 7080", 13))
term.str (string(">>>"))
term.str (RomEngine.readByte(7080))
term.str (string("<<<"))
The end result is >>><<< which means there is nothing stored in the EEProm.What am I doing wrong?
Comments
In the first code, it reads back the location and prints the string to the terminal. Since "123" is no longer at that location in your second code. It's probably trying to display some unprintable ASCII character.
Try adding this to the bottom of your code:
DAT testString byte "123", 0
EDIT: This is wrong. I'm fixing it now. Not fixed yet, sorry.
Then instead of using:
RomEngine.writeByte(7080, "1"))
In your first code, use:
RomEngine.writeByte(7080, @testString)
Edit again: Sorry this wont work either. The location of testString will change between the two programs. I've got to go. If someone else hasn't helped you, I'll help later.
And you really should be writing and reading a word to the EEPROM since memory location can be higher that 255 (the limit of one byte).
Or you could try the following program (attached) I created by modifying the Monitor object Chip Gracey wrote. It will let you read/write individual EEPROM locations. I use this to troubleshoot EEPROM connections.
My EEPROM writing problem is still a mystery...
CON _clkmode = rcfast OBJ RomEngine: "Basic_I2C_Driver" term : "Parallax Serial Terminal" PUB Main term.Start(115200) term.str(string("Init routine",13)) RomEngine.Initialize (28) '(dataPinNumber, clockPinNumber, lockNumberToUse) waitcnt (10000000+cnt) term.str(string("Start routine",13)) RomEngine.Start (28) term.str(string("hello",13)) waitcnt (10000000+cnt) term.str(string("writing 123 to eeprom memory location 8090",13)) RomEngine.writeByte(28,0,8090, 3) '(EEPROMaddress, value) waitcnt (10000000+cnt) term.str(string("pausing just incase", 13)) waitcnt (10000000+cnt) term.str (string("reading from memory location 8090", 13)) term.str (string(">>>")) term.str (RomEngine.ReadByte(28, 0, 8090)) term.str (string("<<<"))
Here is the display of my terminal window showing that no data has been stored to the Gadget Gangster EEPROM
Start routine
writing 123 to eeprom memory location 8090
pausing just incase
reading from memory location 8090
>>><<<
So the EEPROM Monitor did not work for you either?
Most Prop systems have a 64kB eeprom and you can use the upper 32k for general storage...
That is very small and simple and easy to use.
Mike Green has a more versitile version in OBEX
Propeller Eeprom.spin (from the PE Kit Lab)
http://forums.parallax.com/showthrea...271#post678271
The EEPROM monitor/dump works amazingly well.
My problem is still not solved.
The Propeller Eeprom object only suppots copying from ram to rom and from rom to ram in a range of addresses. Thats not what I am trying to do here.
I would love to write a byte (just one little tiny byte) to a know location in the EEPROM, then successfully recall it.
We are getting off topic here.
Using the above code (which by all right should work). I cannot successfully write to an AT24C512. This is annoying, I can watch the Propeller Tool do a successful write but none of the i2c objects work.
Here is another simple sample using another i2c object that does not work. Im sure I am doing something wrong, but cant figure out what that might be.
CON _clkmode = rcfast OBJ RomEngine: "Basic_I2C_Driver" term : "Parallax Serial Terminal" PUB Main outa[28]~ dira[28]~ outa[29]~ dira[29]~ term.Start(115200) term.str(string("Init routine",13)) RomEngine.Initialize (28) '(dataPinNumber, clockPinNumber, lockNumberToUse) waitcnt (10000000+cnt) term.str(string("Start routine",13)) RomEngine.Start (28) term.str(string("hello",13)) waitcnt (10000000+cnt) term.str(string("writing 123 to eeprom memory location 8090",13)) RomEngine.writeByte(28,0,8090, 3) '(SCL, devSel, addrReg, data) waitcnt (10000000+cnt) term.str(string("pausing just incase", 13)) waitcnt (10000000+cnt) term.str (string("reading from memory location 8090", 13)) term.str (string(">>>")) term.str (RomEngine.readByte(28,0,8090)) '(SCL, devSel, addrReg) term.str (string("<<<"))
I wanted to upload a small routine into the EEPROM that wrote to itself, then upload a different routine into RAM ONLY that would check the EEPROM and confirm that the former routine wrote to the EEPROM.
For whatever reason, this dosent work. Maybe someone can explain why...
Very weird...
CON [COLOR="red"] _clkmode = XTAL1|PLL16X _xinfreq = 5_000_000 [/COLOR] OBJ RomEngine: "Basic_I2C_Driver" term : "Parallax Serial Terminal" PUB Main term.Start(115200) waitcnt(clkfreq*3 + cnt) term.str(string("Init routine",13)) RomEngine.Initialize (28) '(dataPinNumber, clockPinNumber, lockNumberToUse) waitcnt (10000000+cnt) term.str(string("Start routine",13)) RomEngine.Start (28) term.str(string("hello",13)) waitcnt (10000000+cnt) term.str(string("writing 123 to eeprom memory location 8090",13)) RomEngine.writeByte(28,[COLOR="red"]RomEngine#EEPROM[/COLOR],8090, 123) '(SCL, devSel, addrReg, data) waitcnt (10000000+cnt) term.str(string("pausing just incase", 13)) waitcnt (10000000+cnt) term.str (string("reading from memory location 8090", 13)) term.str (string(">>>")) term.[COLOR="red"]dec[/COLOR] (RomEngine.readByte(28,[COLOR="red"]RomEngine#EEPROM[/COLOR],8090)) '(SCL, devSel, addrReg) term.str (string("<<<")) DAT
The _clkmode change is mainly for the serial terminal. You won't get 115k2 with RCFAST.It looks like kuroneko has you pointed in the right direction.
I personally use Propeller EEPROM for my EEPROM needs. Here's a little program to write and read a few bytes to EEPROM.
CON _CLKMODE = XTAL1 + PLL16X _CLKFREQ = 80_000_000 _DebugBaud = 57600 OBJ Eeprom : "Propeller Eeprom" Debug : "fullduplexserial" PUB Main | localIndex Debug.start(31, 30, 0, _DebugBaud) waitcnt(clkfreq / 1000 + cnt) ' wait for serial driver cog to start repeat while debug.rxcheck == -1 if result++ // 40 == 0 ' result is a temporary variable all methods have. Debug.str(String(13, "Press any key to start.")) waitcnt(clkfreq / 10 + cnt) ' This line waits a tenth of a second Debug.str(String(13, 13, "Writing ", 34)) Debug.str(@testBuffer) Debug.str(String(34," to EEPROM location $")) Debug.hex($7000, 4) Eeprom.FromRam(@testBuffer, @testBuffer + 2, $7000) Debug.str(String(13, 13, "Reading from EEPROM location $")) Debug.hex($7000, 4) Eeprom.ToRam(@emptyBuffer, @emptyBuffer + 2, $7000) Debug.str(String(13, "The following was read from EEPROM: ", 34)) Debug.str(@emptyBuffer) Debug.tx(34) repeat ' keep program alive DAT testBuffer byte "123",0 emptyBuffer byte 0[4] ' leave a terminating zero
I loaded the above to EEPROM and ran the program. I then loaded the following to RAM only.
CON _CLKMODE = XTAL1 + PLL16X _CLKFREQ = 80_000_000 _DebugBaud = 57600 OBJ Eeprom : "Propeller Eeprom" Debug : "fullduplexserial" PUB Main | localIndex Debug.start(31, 30, 0, _DebugBaud) waitcnt(clkfreq / 1000 + cnt) ' wait for serial driver cog to start repeat while debug.rxcheck == -1 if result++ // 40 == 0 ' result is a temporary variable all methods have. Debug.str(String(13, "Press any key to start.")) waitcnt(clkfreq / 10 + cnt) ' This line waits a tenth of a second { Debug.str(String(13, 13, "Writing ", 34)) Debug.str(@testBuffer) Debug.str(String(34," to EEPROM location $")) Debug.hex($7000, 4) Eeprom.FromRam(@testBuffer, @testBuffer + 2, $7000) } Debug.str(String(13, 13, "Reading from EEPROM location $")) Debug.hex($7000, 4) Eeprom.ToRam(@emptyBuffer, @emptyBuffer + 2, $7000) Debug.str(String(13, "The following was read from EEPROM: ", 34)) Debug.str(@emptyBuffer) Debug.tx(34) repeat ' keep program alive DAT 'testBuffer byte "123",0 emptyBuffer byte 0[4] ' leave a terminating zero
This is the output from the two programs.
Press any key to start. Writing "123" to EEPROM location $7000 Reading from EEPROM location $7000 The following was read from EEPROM: "123" Press any key to start. Reading from EEPROM location $7000 The following was read from EEPROM: "123"
I'm attaching the first program as an archive.
Your troubles in using "Basic_I2C" were caused in part by using incorrect parameter.
You've also been using the wrong data types in many of your programs. You originally were writing a memory location to EEPROM not what was stored in the memory location.
You might want to take a look at this thread.
It has a lot of good information about using Mike Green's Basic_I2C_Driver (including some examples by Mike).
kuroneko's corrections might make more sense after you read it.
David,
My goal in providing the example code was not to solve your problem but rather to provide an alternate means of verifying your EEPROM was able to be read/written properly by a known working object. Based on the name of the object you are using and my lack of familiarity with it I would not be able to provide details for that object. That object, by name, referenced ROM and I was trying to provide EEPROM access, which is what you wanted. At this point I will defer this to those who can help with the object you're trying to use. The only reference to the object I could find was the following thread where another member was also having issue reading/writing the EEPROM.
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F%2Fforums.parallax.com%2Fshowthread.php%3F124857-Trouble-with-simple-RomEngine-and-TV.text-program.&ei=5mwQT_TFPOORiQLdx7W8DQ&usg=AFQjCNFekjwULFonWEBrE_AmGV3TZb_JOA&sig2=Jgk_StpuzvttKvz8Fh8oUQ