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 Slave (read command)

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



Joined: 20 Jul 2006
Posts: 15

View user's profile Send private message

I2C Slave (read command)
PostPosted: Mon Oct 16, 2006 3:25 pm     Reply with quote

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.
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