|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
How to write an entire page of data to an EEPROM |
Posted: Fri Jun 24, 2005 5:27 am |
|
|
Hi,
Compiler: PCM
MCU : 16F628
Is it possible to write to an 24LC256 serial eeprom page wise, if so howe ???
thanks
arunb |
|
|
Ttelmah Guest
|
|
Posted: Fri Jun 24, 2005 6:02 am |
|
|
Arrow has been posting code to do exactly this (with a lot of discussion of why it is running slower than he expects).
The key thing is just to write the first byte to the start of the page, and then just keep writing the bytes for the entire page size. Only once all the bytes are sent, do you then issue the 'stop' command.
So for the S4LC16 (for example), using the definitions already in the 2416.c file, give:
Code: |
//Here data is passed as the _address_ of a 16 byte buffer
void write_ext_eeprom(long int address, BYTE *data) {
int8 ctr;
while(!ext_eeprom_ready());
i2c_start();
i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
i2c_write(address);
for (ctr=0;ctr<16;ctr++) i2c_write(data[ctr]);
i2c_stop();
}
|
The write will actually start, when the 'stop' condition is sent. If the code is called again immediately, it'll sit in the 'wait for ready' loop, until the write finishes. Ideally your processor can go off and do something else for the time involved. Also the starting 'address', should be on a page boundary.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|