I2C EEPROM Block Write Help?

Hello,

I have just started working with a variety of I2C components for a timer/clock project and have been really liking the ease and efficiency of use for small data (byte by byte transmission, etc). Currently I am mainly trying to work with the DS3231I Real Time Clock and AT24C32 I2C EEPROM

(Found here http://www.banggood.com/DS3231-AT24C32-IIC-High-Precision-Real-Time-Clock-Module-For-Arduino-p-81066.html ).

Once I get these working together I’d like to print via 16x2 I2C LCD . I have worked through a few of the different compiled libraries for I2C for Arduino and have yet to come across a function similar to a avr/eeprom.h library’s EEPROM block write/read function
(e.g. eeprom_write_block((const void*)&datastructure, (void*)startaddress, sizeof(datastructure));)

I would like to store a small data structure of a variety of program settings, variables, and sensor data in the AT24C32 via I2C since it is battery powered, so that I could have these saved in the event of a power loss. If anyone has any idea how to do this, my programming skills are quite minimal and I don’t want to read a whole data structure in byte by byte (manually) unless that is the only option. If anyone has a library that would do this or knows where to find one or a quick way to implement this it’d be much appreciate. Thanks ahead of time!

Regards,

LP

If anyone has any idea how to do this

You could always look at the source code for the function, to see the loop that they used to write the individual bytes to individual addresses.

I don't want to read a whole data structure in byte by byte (manually) unless that is the only option.

A for loop makes that trivial. Why are you opposed to using a for loop?

Not opposed to using the for loop at all, just wasn't sure reading it in that way would allow for some of the structure sizes I wanted either, I could definitely do that - I just love the ease of the EEPROM write functions taking care of all the addresses for me, and in my 7 years of (minimal) programming, I still make mistakes and may get an address wrong from time to time, and would like this to be solidified ahead of time so I can frequently change the structure and have it be read out knowing int a = 5, float b = 5.3949323, and hopefully things like time-stamping a series of data logs, making them all together in one entry. I know this is possible with a for loop and then indexing each individually by address, but that will take a while to set up, and every time I change anything in code I will have to re index every address, and surely (maybe due to my bad sight) I will make a mistake and this will take a lot longer than using a working library, or possibly making my own. If you still think this would be simple maybe I am just not seeing how - Thanks for the reply/suggestions!

I don't know which library you're using, but within the library I'm using I have

__ writePage(word address, byte* data, int length)__

Does this cover what you want?

Ken,

Thanks! I think that may be what I need, but I have yet to try it. I will give er a try here a in a minute. Thanks again!

You're welcome. There's also the complement function int readPage(word address, byte* data, int length)

How about this?

http://playground.arduino.cc/Code/EEPROMWriteAnything

Nick,

Thank you (for this and all of your great Arduino support)! This is my absolute favorite EEPROM library and I have used it on the Atmel chip's EEPROM quite frequently/comfortably, I am curious if there is a way to implement this into writing to the AT24C32's EEPROM (over i2c)? (There may be another way to go about achieving what i need to do, but I am unsure) Essentially, I just want to be able to save the time/date (hopefully also some sensor data) info from the DS3231 on the battery powered EEPROM as it progresses so that I can keep updating it during the event of a power loss. This way, I could read that data and the clock will still be accurate when the power would come back on.

Any help is much appreciated. Thanks again!

Regards,

LP

check - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

Essentially, I just want to be able to save the time/date (hopefully also some sensor data) info from the DS3231 on the battery powered EEPROM as it progresses so that I can keep updating it during the event of a power loss.

The DS3231 is designed to keep the time and date over a power failure, that's why it has a battery interface. The memory that is battery powered is a small portion of RAM and not an EEPROM. The difference is important: an EEPROM wears off by writing to it while a RAM cell may be written as often as you want. So you can store some data in that non-volatile RAM of the DS3231 but it's absolutely unnecessary to store the date/time there as the chip keeps track of it anyway.

Thanks - to both of you.

I'd like to look into this RAM first,

The DS3231 is designed to keep the time and date over a power failure, that's why it has a battery interface. The memory that is battery powered is a small portion of RAM and not an EEPROM. The difference is important: an EEPROM wears off by writing to it while a RAM cell may be written as often as you want. So you can store some data in that non-volatile RAM of the DS3231 but it's absolutely unnecessary to store the date/time there as the chip keeps track of it anyway.

As far as saving in RAM, I am not sure the library I'm using utilizes this feature. Whenever I power off the Arduino it resets the time to ~11:59. Is there a library you use that implements this? (I'm using Edward Comer's DS3231 Library). If not, how do you manage to use that functionality of the RTC?

jengil:
This is my absolute favorite EEPROM library and I have used it on the Atmel chip’s EEPROM quite frequently/comfortably, I am curious if there is a way to implement this into writing to the AT24C32’s EEPROM (over i2c)?

In addition to what Rob said, I had an I2C version here:

http://www.gammon.com.au/forum/?id=10896&reply=8#reply8

Not that this specifically addressed that EEPROM, but the concept is the same.

As far as saving in RAM, I am not sure the library I'm using utilizes this feature. Whenever I power off the Arduino it resets the time to ~11:59. Is there a library you use that implements this? (I'm using Edward Comer's DS3231 Library). If not, how do you manage to use that functionality of the RTC?

I don't use a library, I just wrote the necessary routines for my project myself. Please provide a link to that library, Google doesn't seem to know it.

this one might be interesting too - https://github.com/JChristensen/DS3232RTC -

Jack Christensen has also written an I2C eeprom library which I have used. It block writes/reads, handles page size, and writing over the end of the EEPROM.

https://github.com/JChristensen/extEEPROM