View previous topic :: View next topic |
Author |
Message |
jspencer
Joined: 22 Dec 2003 Posts: 57 Location: Boise, ID USA
|
I2C Page read and page write |
Posted: Fri Mar 10, 2006 2:50 pm |
|
|
Just want to make sure that this looks correct for doing page reads and writes. I know that the writes are page bound, but I'm reading and writing on the 32 byte boundries so it's not an issue. I'm only getting the first byte of the read and the write is working correctly.
Thanks,
jspencer
Code: |
void page_read(int8 *mem_address, int16 start_address) {
int8 i;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(start_address));
i2c_write(start_address);
i2c_start();
i2c_write(0xa1);
for (i=0;i<32;i++)
*(mem_address + i) = i2c_read(i);
i2c_stop();
}
void page_write(int8 *mem_address, int16 start_address) {
int8 i;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(start_address));
i2c_write(start_address);
for (i=0;i<32;i++)
i2c_write(*(mem_address + i));
i2c_stop();
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 10, 2006 2:59 pm |
|
|
Look in the CCS manual at the specification for the i2c_read() function.
Does it accept the parameters that you are giving it ?
Also, what parameter should be used for the initial bytes of a
multi-byte read, and what should the parameter be on the last byte ? |
|
|
jspencer
Joined: 22 Dec 2003 Posts: 57 Location: Boise, ID USA
|
|
Posted: Fri Mar 10, 2006 3:10 pm |
|
|
Doh! I guess that's what I get for not looking at the manual before asking the question. ACK the first 31 bytes and NACK the last byte before the stop. Works great now.
Thanks PCM. |
|
|
|