CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I2C Page read and page write

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

I2C Page read and page write
PostPosted: Fri Mar 10, 2006 2:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 2:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 10, 2006 3:10 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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