View previous topic :: View next topic |
Author |
Message |
info@ckmintech.com
Joined: 16 May 2006 Posts: 39
|
First Read or Write after I2C start |
Posted: Mon Dec 14, 2009 7:29 pm |
|
|
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
|
|
|
info@ckmintech.com
Joined: 16 May 2006 Posts: 39
|
|
Posted: Tue Dec 15, 2009 1:12 am |
|
|
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
|
|
Posted: Tue Dec 15, 2009 3:21 am |
|
|
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
|
|
Posted: Tue Dec 15, 2009 10:13 am |
|
|
Thanks |
|
|
|