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 support@ccsinfo.com

First Read or Write after I2C start

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

First Read or Write after I2C start
PostPosted: Mon Dec 14, 2009 7:29 pm     Reply with quote

We need to setup a slave I2C to send a sequence of data or read a sequence of data after a I2C start. As we need to read / write from a starting position we need to reset the pointer to the first location after a I2C start and the pointer will increase by one for every subsequence read/write.

Question - Is there any notification or event that will fry after the I2C start or how can I know this is the FIRST read/write request after I2C start?

Thanks for any advice.

Rgds.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 14, 2009 10:37 pm     Reply with quote

Use the i2c_isr_state() function for this. See that section in the CCS manual.

This thread may also help with sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=39565

This thread may answer other questions:
http://www.ccsinfo.com/forum/viewtopic.php?t=40796
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

PostPosted: Tue Dec 15, 2009 1:12 am     Reply with quote

Thanks PCM Programmer.

I know how to use i2c_state() but I need to write the first read data after i2c start to location 0, second data to location 1 and so on.. The master will then send i2c stop. The master will send i2c start, data again next time it need to send data.

Therefore I need to reset the internal pointer whenever a new i2c start. Is there any solution for this?

i2c_state() can tell me read or write only.

Rgds.
Ttelmah
Guest







PostPosted: Tue Dec 15, 2009 3:21 am     Reply with quote

The first transaction after a start in I2C, is always a _write_. It is the device address. You can detect when this arrives, and then reset your pointer. I2C, does not support a start followed by an immediate read.
I2C_ISR_STATE, returns '0x80', for address match, with R/W set (which is what your address will need), and when you see this, clear the counter.
The I2C hardware won't support starting with a read (impossible anyway, since the slave always _responds_ to master requests, and data would not be loaded)
The sequence for sequential reads is:
MASTER SLAVE
I2C start
I2C write device address R set. Sees address, loads first byte
I2C read first byte Loads next byte

etc..

Remember the NACK when the sequence is complete.

Best Wishes
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

PostPosted: Tue Dec 15, 2009 10:13 am     Reply with quote

Thanks
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