pr83
Joined: 20 Jul 2006 Posts: 15
|
I2C Slave (read command) |
Posted: Mon Oct 16, 2006 3:25 pm |
|
|
I have two questions!!
1. Since the control byte for the READ or WRITE command is as follows:
Bit 0, 1, 2, 3 : Slave address
Bit 4,5,6 : Don’t care
Bit 7: R/W
I have 2 situations when the Master needs to get 2 different data from the Slave.
I wanted to know if the Master can always call a command with the R/W bit set.And only have to change the don’t care bits for the slave to know which data to send to the Master?
Ex:
1st Case:
Code: |
Master would call:
i2c_start();
write(0x5F) //R/W bit Set
data[1] = i2c_read();
..
..
..
i2c_stop();
|
SLAVE would respond with:
Code: |
if(i2c_isr_state() == 0x80) //Master is Requesting data
{
incoming = i2c_read();
if (incoming == 0x5F)// The address the Master sent with the R/W bit set
{
i2c_write(data[0]);
}
}
|
2ND Case:
All I change here is 5F to 5E. This just changes the ‘Don’t care’ bits. And leaves the rest the same.
So,
Master would call:
Code: |
i2c_start();
write(0x5D) //R/W bit Set
data[1] = i2c_read();
…
…
…
i2c_stop();
|
Slave would respond with:
Code: |
if(i2c_isr_state() == 0x80) //Master is Requesting data
{
incoming = i2c_read();
if (incoming == 0x5D) // The address the Master sent with the R/W bit set
{
i2c_write(data[0]);
}
}
|
2. My worry is that when I call : incoming = i2c_read();
Am I reading the 0x5F or 0x5D that was sent to the Slave by the Master right before i2c_isr_state() returned 0x80.
In other words when we start a new i2c routine. And the Mater writes the address of the slave with the W/R set. Then if I call a i2c_read() in the slave within the if statement for (i2c_isr_state() ==0x80 ). Do I get the same address that was written by the master to make the i2c_isr_state() return 0x80 in the first place.
Thanks. |
|