PE Kit Lab Applications EEPROM Datalogging and I2C
Andy Lindsay (Parallax)
Posts: 1,919
PE Kit Lab Applications – EEPROM Datalogging and I2C··
Attached is the first application installment for the next Propeller Education Kit lab – EEPROM Datalogging and I2C.· Test Propeller Eeprom v0.677...zip is a HyperTerminal application for testing the Propeller Eeprom object’s VarBackup, VarRestore, FromRam, and ToRam methods.· It allows you define values stored by selected array elements and then copy the array from main RAM to EEPROM and visa versa.·
·
Example:
·
VAR
· long values[noparse][[/noparse]32]
·
OBJ
· eeprom : “Propeller Eeprom”
·
PUB Main
· ...
· eeprom.VarBackup(@values, @values[noparse][[/noparse]31] + 3)··· ‘ Backup
· ...
· eeprom.VarRestore(@values, @values[noparse][[/noparse]31] + 3)······· ‘ Restore
·
One interesting and particularly useful application of the Propeller Eeprom object’s VarBackup method is that values that were copied from the main RAM’s variable memory to EEPROM are automatically restored to variable memory on reboot.· (Thanks and kudos to Jeff Martin for suggesting this approach!)· The VarRestore method can also be used to programmatically restore variable memory to an earlier state that was copied to EEPROM by VarRestore.
·
The zip’s Propeller Eeprom object also has FromRam and ToRam methods for datalogging values to portions of EEPROM not used for program and variable storage.·
·
Example:
·
·· ...
·
·· ‘ Copy array to EEPROM starting at eeAddr to eeAddr + 127.
·· eeprom.FromRam(@value, @value[noparse][[/noparse]31] + 3, eeAddr)
·
·· ...
·
·· ‘ Copy from eeAddr to eeAddr + 127 to value[noparse][[/noparse]0]..value[noparse][[/noparse]31].
·· eeprom.ToRam(@value, @value[noparse][[/noparse]31] + 3, eeAddr)
·
Please send corrections to editor@parallax.com, and post suggestions and recommendations to this thread.
·
PE Kit Labs that have already gone through the review process are available for download from the Propeller Education Kit page.· You can also find discussions for each lab along with the latest drafts in progress on the Propeller Education Kit Labs thread.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:32:19 PM GMT
Attached is the first application installment for the next Propeller Education Kit lab – EEPROM Datalogging and I2C.· Test Propeller Eeprom v0.677...zip is a HyperTerminal application for testing the Propeller Eeprom object’s VarBackup, VarRestore, FromRam, and ToRam methods.· It allows you define values stored by selected array elements and then copy the array from main RAM to EEPROM and visa versa.·
·
Example:
·
VAR
· long values[noparse][[/noparse]32]
·
OBJ
· eeprom : “Propeller Eeprom”
·
PUB Main
· ...
· eeprom.VarBackup(@values, @values[noparse][[/noparse]31] + 3)··· ‘ Backup
· ...
· eeprom.VarRestore(@values, @values[noparse][[/noparse]31] + 3)······· ‘ Restore
·
One interesting and particularly useful application of the Propeller Eeprom object’s VarBackup method is that values that were copied from the main RAM’s variable memory to EEPROM are automatically restored to variable memory on reboot.· (Thanks and kudos to Jeff Martin for suggesting this approach!)· The VarRestore method can also be used to programmatically restore variable memory to an earlier state that was copied to EEPROM by VarRestore.
·
The zip’s Propeller Eeprom object also has FromRam and ToRam methods for datalogging values to portions of EEPROM not used for program and variable storage.·
·
Example:
·
·· ...
·
·· ‘ Copy array to EEPROM starting at eeAddr to eeAddr + 127.
·· eeprom.FromRam(@value, @value[noparse][[/noparse]31] + 3, eeAddr)
·
·· ...
·
·· ‘ Copy from eeAddr to eeAddr + 127 to value[noparse][[/noparse]0]..value[noparse][[/noparse]31].
·· eeprom.ToRam(@value, @value[noparse][[/noparse]31] + 3, eeAddr)
·
Please send corrections to editor@parallax.com, and post suggestions and recommendations to this thread.
·
PE Kit Labs that have already gone through the review process are available for download from the Propeller Education Kit page.· You can also find discussions for each lab along with the latest drafts in progress on the Propeller Education Kit Labs thread.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:32:19 PM GMT
Comments
For datalogging though, I just ordered some extra 24LC128 chips to add to the I2C bus... Do you think that "Propeller Eeprom.spin" will work with this chip too? I guess it depends on if the page boundaries are the same, right? But, I see the number 64 in this line:
page := addr+64-eeAddr//64<#endaddr+1 ' Find next EEPROM page boundary
So, I guess it has the same 64 byte page boundary.
I wish you had the chip address as a variable, but it looks like these lines send the address:
SendByte(%10100001) ' EEPROM I2C address + read operation
ackbit := SendByte(%10100000) ' Write command with EEPROM's address
I think this means the built in eeprom is assumed to have all chip select pins low for address #0. Is there anything else to do to talk to a different chip?
Very timely.
I hope the discussion section includes pointers to I2C links and a brief discussion of I2C vs SPI.
Rayman... you asked the question better than I could have[noparse]:)[/noparse]
Rich
This app is the foundation for the first part of the lab which is about memory architecture, and datalogging. The Propeller Eeprom object for this first part is supposed to be as light as possible. It's currently 93 longs, and I will be whittling away to make it smaller and faster before the lab comes out.
The second part of the lab will be about I2C. It will start by adding the 10 k pullup resistor to the 24LC256’s SCL line. Then, it will develop an I2C object step-by-step. It'll be a good exercise in starting with a timing diagram and specification and writing code implements it. It'll also be a good exercise in breaking a coding problem into its elements. For example, after the start condition and address byte have been written, test to see that the Propeller's EEPROM replies to its own address with an acknowledge (0) and to a different address with a no acknowledge (1). Stuff like that…
Here are links to I2C drivers that you can currently use for your projects. (Just did a search.) Most of them should work for your (Rayman’s) requests.
Existing I2C Objects
(Everybody: Please PM me with entries that need to be added to this list! Thanks.)
·- Mike Green’s Basic I2C Driver on Propeller Object Exchange·-> Data Storage
·- James Burrows’ i2c Object Examples, also on Propeller Object Exchange -> Data Storage
·- Eric’s tiny_i2c (Forum post)
·- Beau Schwabe’s I2C (Forum post)
·- Andre' LeMothe’s Hydra Game System Kit (EEPROM Product page)
Looks like I might need to add a third section…something like, now that you understand I2C from the inside out, let’s apply the nomenclature we picked up along the way to do the same job with an I2C driver from the object exchange.
Andy
P.S. Rich, good idea about the I2C vs. SPI.· Will-do
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:32:57 PM GMT
Thanks for these objects. The Propeller Eeprom object has helped me to keep track of file names used in data logging (each time the logger is started it uses a new file name for the data). I recently needed to modify the object to leave pins 28 and 29 low and as inputs after the necessary read or write has been preformed. I found the original Propeller Eeprom object was interfering with another object using pins 28 and 29.
I added this method:
I added a call to I2cEnd at the end of FromRam and ToRam methods. This ended the conflict the object was causing.
Duane
I was just wondering if an actual lab, that explains all of this in english, has ever been released. I know it's always fun to reverse engineer how things work and how to interface to Objects by poring over various sections of code, test demos, etc. and dreaming of copious comment lines, but once in a while I like curling up by a warm fire with a cold beverage and the english translation. Might there even be a draft version somewhere on hand?
I can find no copyright or licensing info with the source code.
It looks perfect for my application, but since my project is potentially commercial in nature, I need to know the licensing status.
I think the files need to be updated to include such if it's going to be released for use.
I don't want to assume.
Brian
Did you try looking for the same or similar code in the Object Exchange (OBEX)? I think most of the code in the OBEX should have some sort of license statement.
http://obex.parallax.com/search/eeprom
From the OBEX welcome page.... http://obex.parallax.com/
"All objects and snippets on the Propeller Object Exchange are provided under the MIT License. "
I had looked there, but based on descriptions alone, nothing sounded quite right, mostly too generic. The "propeller eeprom" is perfect, which I found referenced by searching the forums for other threads talking about this. This is my first attempt and this task, writing data to the eeprom.
I guess I'll have to start downloading all the stuff in the OBEX and actually look at the code.
Brian
I can't speak for Parallax but what you want to use is almost certainly under the same MIT license as what's in the OBEX, so why not email Parallax and just ask them directly?
That was my plan if I didn't find a good answer via the thread. Since it was posted by Andy, I'll email him directly.
Brian