View Full Version : Saving data in an application
02-08-2007, 12:04 AM
I would like to save some values for later use by the propeller. I am reading a count and would like to save that information so that the next time when I turn the unit on it can read that previous count. Please excuse me if I am not asking the question correctly.
Thanks in advance!
Since the prop usually has an I2C 32k eeprom connected for booting, this shouldn't be too tough. If it is Spin code that you are writing it in, you could use the DAT directive to load in data into the prop. If you store your program to eeprom, after you power up, it will load the data from eeprom. Your program could just overwrite the data byte in the eeprom via I2C. Be careful, however, because this self is close to self modifying code, and one mistake can be a real pain to debug.
02-08-2007, 12:27 AM
You can save information in the end of the EEPROM (much the same as with the Stamps) since programs are loaded beginning at location zero. When you download a new program, the first 32K of the EEPROM is cleared, so you'll lose any stored data if the EEPROM is only 32K. There are two different I2C drivers in the Propeller Object Exchange. Either will work for this.
02-08-2007, 01:40 AM
I have been using the 512byte fram chip ( its accross the page from the microchip eeproms in the mouser catalog). I have it connected to the OS eeprom pins and have the address pins set different than the os eeprom. I set a cog running that checks A given address and loads the fram every second.(using the ctra)On startup my main program loads the address with the fram value. I am using the i2cobject from the object exchange with a few mods to directly load long values. You need to be careful that you don't load values to the eeprom in a loop or you may burn it out. 1,000,000 cycles they say I don't know.
02-08-2007, 05:04 AM
Mike Green has given examples in previous posts - I used similar to write/read to/from a second eeprom - using the same code except editing the pin no.'s for SDA,SCL - mike has a minimal_i2c_driver example out there. My 2nd eeprom is used to store settings - which are rarely changed - so the finite amount of write cycles is not an issue. If your write requirements are very frequent - why not consider the SD card option by Rokicki
Have a look at the following for some pointers:
this discusses extra storage - eeprom or SD card..
the following is specifically for I2C / EEProm the example given here is for the boot eeprom but if you wanted to add an additional eeprom to other pins - just edit pin no.'s .
Or otherwise 'bussed' devices on same lines with different addresses -
note - Its a philips protocol - worth reading - especially master/slave - some legalities there..
and if you go the SD card route:
either way when it comes to I2C - Mike Green is the man or SD card its Rokicki !!
Thats my humble opinion at least...
02-08-2007, 12:27 PM
When writing to eeprom how do you know where it is putting it and how do you know where to retrieve it?
Can someone post a snippet of code?
02-08-2007, 12:51 PM
There is a snippet of code in the comments of the Simple_I2C_Driver in the Propeller Object Exchange.
There are similar examples in the I2C Library in the Object Exchange. If you have any questions after
you've looked at them, ask here specifically. Pretty much all of the objects in the Object Exchange have
Demo Programs as part of their archive that illustrate their use. They often include circuit diagrams for
the connection of the related parts.
02-08-2007, 02:52 PM
The key to what you want to do is to allocate a space for the data you want to keep, and keep track of the absolute address of the data space. There are a few ways to do this, but you should follow Mike's advice first and understand how to access the data.
Paul Baker (mailto:email@example.com)
Propeller Applications Engineer
Parallax, Inc. (http://www.parallax.com)
02-08-2007, 11:50 PM
Thanks very much for your help. I have looked at some of the examples and have successfully wrote to and read from. This is a big deal for me!! I still need to work on the theory part......