View previous topic :: View next topic |
Author |
Message |
Alphada
Joined: 19 Jun 2017 Posts: 27
|
Library for a 24LC512 serial EEPROM question |
Posted: Thu Jul 27, 2017 6:52 am |
|
|
Code: | void write_ext_eeprom(EEPROM_ADDRESS locEE, unsigned int8 data)
{
disable_interrupts(global);
unsigned int8 status;
i2c_start(SHARED_STREAM_I2C_EEPROM);
i2c_write(SHARED_STREAM_I2C_EEPROM, EEPROM_SLAVE_ADDRESS);
i2c_write(SHARED_STREAM_I2C_EEPROM, make8(locEE, 1));
i2c_write(SHARED_STREAM_I2C_EEPROM, make8(locEE, 0));
i2c_write(SHARED_STREAM_I2C_EEPROM, data);
i2c_stop(SHARED_STREAM_I2C_EEPROM);
do
{
i2c_start(SHARED_STREAM_I2C_EEPROM);
status = i2c_write(SHARED_STREAM_I2C_EEPROM, EEPROM_SLAVE_ADDRESS);
} while(status==1);
i2c_stop(SHARED_STREAM_I2C_EEPROM);
enable_interrupts(global);
} |
Is this code absolutely necessary? and which is, its purpose?
Code: | do
{
i2c_start(SHARED_STREAM_I2C_EEPROM);
status = i2c_write(SHARED_STREAM_I2C_EEPROM, EEPROM_SLAVE_ADDRESS);
} while(status==1);
i2c_stop(SHARED_STREAM_I2C_EEPROM); |
also is it possible to write sequentially at arbitrary addresses? or its the adress only specified at just after the start? where can i find info about it.
Thanks in advance! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jul 27, 2017 7:15 am |
|
|
Working backwards....
The BEST place to get information about the 24LC512 is from manufacturer. I just downloaded the Microchip datasheet for their device.
Yes, you can write at any individual address, check the chapter called 'write operations' in the datasheet.
You also need to know that every 'single' byte write will take up to 5ms. So if you want to save 100 bytes that will take up to 1/2 second.
Now there is a 'page ' write option and by using it, you can store the same 100 bytes of data in just 5 ms !! A 'page' for this device is 128 bytes, so a clever programmer will create a RAM buffer of 128 bytes and write a page as it's a LOT faster.
How you write to the device will depend upon how much data you need to save at one time and how often. Typically my 'datalogger' will store data in RAM until the buffer is full OR a time limit is tripped.
As for the code ... it might be a 'wait until ready' function or a 'release the bus' function. Just contact the original coder and ask.
Jay |
|
|
Alphada
Joined: 19 Jun 2017 Posts: 27
|
|
Posted: Thu Jul 27, 2017 7:22 am |
|
|
temtronic wrote: | Working backwards....
The BEST place to get information about the 24LC512 is from manufacturer. I just downloaded the Microchip datasheet for their device.
Yes, you can write at any individual address, check the chapter called 'write operations' in the datasheet.
You also need to know that every 'single' byte write will take up to 5ms. So if you want to save 100 bytes that will take up to 1/2 second.
Now there is a 'page ' write option and by using it, you can store the same 100 bytes of data in just 5 ms !! A 'page' for this device is 128 bytes, so a clever programmer will create a RAM buffer of 128 bytes and write a page as it's a LOT faster.
How you write to the device will depend upon how much data you need to save at one time and how often. Typically my 'datalogger' will store data in RAM until the buffer is full OR a time limit is tripped.
As for the code ... it might be a 'wait until ready' function or a 'release the bus' function. Just contact the original coder and ask.
Jay |
Thanks alot for real it helped me a lot im gonna analyze the buffer idea. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 27, 2017 9:16 am |
|
|
If you look in the code library:
<http://www.ccsinfo.com/forum/viewtopic.php?t=39135&highlight=eeprom>
This is for the 256Kbit ROM, not the 512, but shows how 'page' reads and writes can be done. Basically check the data sheet and change the page size to match your chip. |
|
|
|