Unable to write a long to EEPROM 24LC256
jmmb392
Posts: 22
in Propeller 1
Hello everybody,
I want to first thank you all for all the previous help that you have provided to me. Once again my name is Jaime Montenegro, this is my first propeller project. I am writing a program that reads the optical ports of several power meters. To accomplish that I first had to be able to detect and time stamp pulses coming from the optical ports; so I first had to setup a RTC clock DS1307 which I did with the help of some of you (Mike Green and Chris Savage) in a previous discussion.
I am currently using a propeller demo board, I have already programmed the propeller to use six cogs to read 6 optical ports coming from 6 power meters and store the values in variables. Now, I want to be able to save those values in a EEPROM for backup and also send those values wirelessly via Xbee.
This is my setup::
RTC DS1307 (kit from adafruit https://www.adafruit.com/product/264 )
EEPROM 24LC256 (EXTERNAL, NOT THE ONE ON THE DEMO BOARD, I HAD TO DO THAT BECAUSE THE ONE IN THE DEMO BOARD USES P28 AND P29, BUT I DO NOT HAVE PHYSICAL ACCESS TO CONNECT THE RTC CLOCK TO THOSE PINS)
EEPROM ADDRESS = %1010000 (GIVEN IN THE SPECS OF THE EEPROM)
SCL = PIN 6
SDA = PIN 7
BAUD RATE = 57600
I am using P0 ..P5 as the inputs for the optical pulses coming from the power meters, I am also running individual cogs per meter, cog1 reads P0, cog2 reads P1 and so on .
I was able to get my hands on 2 different i2c drivers:
Basic I2C Driver
http://obex.parallax.com/object/155
(Suggested by Mike Green)
Very Basic I2C Driver
The other one was given to me by Chris Savage
So I decided to write two different projects for each driver:
PROJECT 1 USING THE: Basic I2C Driver (my code 6b)
I am capable of detecting a pulse with the code and time stamp it. I created an array pdata[8] to hold all my data, and then I send the data to the eeprom via i2c.WriteLong and i2c.WriteByte.
To see if it works, I also created another array rdata[8] to retrieve the values that (supposedly) I had already saved in the eeprom, but all I get is -1. I am attaching the entire project, please take a look at it, I must be doing something wrong but I do not know what.
PROJECT 2 USING THE: Very Basic I2C Driver (my code 8b)
I am capable of detecting a pulse with the code and time stamp it. For this project, I also created an array pdata[8] to hold all my data and another array rdata[8] to retrieve the values that (supposedly) I had already saved in the eeprom. The issue with this driver is that it only has a method to write/read a byte (ByteWrite and RandomRead). I am capable to write to the eeprom and read from it all the variables that are byte size, but I need to write and read from the eeprom a variable with long size (pdata[0] this variable will be higher than 255), and I do not know how to go about it. I am also attaching the entire project, please take a look at it.
Thank you!!
I want to first thank you all for all the previous help that you have provided to me. Once again my name is Jaime Montenegro, this is my first propeller project. I am writing a program that reads the optical ports of several power meters. To accomplish that I first had to be able to detect and time stamp pulses coming from the optical ports; so I first had to setup a RTC clock DS1307 which I did with the help of some of you (Mike Green and Chris Savage) in a previous discussion.
I am currently using a propeller demo board, I have already programmed the propeller to use six cogs to read 6 optical ports coming from 6 power meters and store the values in variables. Now, I want to be able to save those values in a EEPROM for backup and also send those values wirelessly via Xbee.
This is my setup::
RTC DS1307 (kit from adafruit https://www.adafruit.com/product/264 )
EEPROM 24LC256 (EXTERNAL, NOT THE ONE ON THE DEMO BOARD, I HAD TO DO THAT BECAUSE THE ONE IN THE DEMO BOARD USES P28 AND P29, BUT I DO NOT HAVE PHYSICAL ACCESS TO CONNECT THE RTC CLOCK TO THOSE PINS)
EEPROM ADDRESS = %1010000 (GIVEN IN THE SPECS OF THE EEPROM)
SCL = PIN 6
SDA = PIN 7
BAUD RATE = 57600
I am using P0 ..P5 as the inputs for the optical pulses coming from the power meters, I am also running individual cogs per meter, cog1 reads P0, cog2 reads P1 and so on .
I was able to get my hands on 2 different i2c drivers:
Basic I2C Driver
http://obex.parallax.com/object/155
(Suggested by Mike Green)
Very Basic I2C Driver
The other one was given to me by Chris Savage
So I decided to write two different projects for each driver:
PROJECT 1 USING THE: Basic I2C Driver (my code 6b)
I am capable of detecting a pulse with the code and time stamp it. I created an array pdata[8] to hold all my data, and then I send the data to the eeprom via i2c.WriteLong and i2c.WriteByte.
To see if it works, I also created another array rdata[8] to retrieve the values that (supposedly) I had already saved in the eeprom, but all I get is -1. I am attaching the entire project, please take a look at it, I must be doing something wrong but I do not know what.
PROJECT 2 USING THE: Very Basic I2C Driver (my code 8b)
I am capable of detecting a pulse with the code and time stamp it. For this project, I also created an array pdata[8] to hold all my data and another array rdata[8] to retrieve the values that (supposedly) I had already saved in the eeprom. The issue with this driver is that it only has a method to write/read a byte (ByteWrite and RandomRead). I am capable to write to the eeprom and read from it all the variables that are byte size, but I need to write and read from the eeprom a variable with long size (pdata[0] this variable will be higher than 255), and I do not know how to go about it. I am also attaching the entire project, please take a look at it.
Thank you!!
Comments
In the DIY I2C tutorial on the last page is a method for storing integer type values to an eeprom and retrieving back as an integer type.
http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/diy-i2c/more-data-types-and-devices
If you're always reading back a -1, probably the data isn't being written. Remember that the write protect (/WP) pin has to be grounded.
We can't tell you what's going on with the Basic_I2C_Driver without looking at your code. The object does work.
If you want to provide a 3ms or longer delay by doing something else, you don't need to use WriteWait.
The start and stop methods are for internal use only. They are left as PUB methods in case someone wants to write a high-level routine for some other I2C device as some people have done.
Hello guys, I could not work on the project for some time because I was at the hospital. I started working again on it, and was able to write/read the long to the eeprom, I implemented these codes:
To write long to EEPROM:
repeat index2 from 0 to 3
To read long from EEPROM:
I want to thank all of you for your comments and suggestions. Now my next step/challenge is transferring data thru an xbee network. I have a question, does anybody know how to get the data from the eeprom to a PC and save it in a CSV file so I can read it using Excel?
Thank you for your help.