I2C communication

Status
Not open for further replies.

deexith hasan

New Member
I can able to understand transmitting data through I2C..but in receiving data its tough
for me..

in this website i can see 2 SCL and SDA

https://www.robot-electronics.co.uk/acat.../I2C_Tutorial.html
C:
unsigned char i2c_rx(char ack)
   {
   char x, d=0;
   SDA = 1;
   for(x=0; x<8; x++) {
      d <<= 1;
      do {  
         SCL = 1;
      }
      while(SCL_IN==0); // wait for any SCL clock stretching
      i2c_dly();
      if(SDA_IN) d |= 1;
      SCL = 0;
   }
   if(ack) SDA = 0;
   else SDA = 1;
   SCL = 1;
   i2c_dly(); // send (N)ACK bit
   SCL = 0;
   SDA = 1;
   return d;
}

in this program where i cant find any digitalread.....
 
Last edited by a moderator:
I placed your code in "Code" tags to make it easier to read...

If(SDA_IN) d |= 1; .... This line reads the I2C bus..

d <<= 1; ... This line shifts the receive buffer..

This happens for 8 iterations....
 
thanq its now clear that there is read line in I2C rx....but in I2C only 2 pins are needed (SDA,SCL) then what about SDA_IN and SCL_IN pin??
 
Its the same pin.... They are just named so you can read it clearer.. It you look at my tutorials ( I think its Tutorial 6 ) I have made software I2C routines... I have clearly remarked on the operation.. The link is in my signature..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…