Skip to main content

Different Stages of I2C communication

Different Stages Of I2C


So here we are going to understand different stages required while communicating using I2C protocol. Let's have a look at the data frame displayed below.





Now we will discuss each and every stage one by one before going to a simple project
(college minor project)


START Condition:

void i2c_start()
{
SCL=0;
SDA=1;
SCL=1;
SDA=0;
}


So in start condition, serial clock goes low to high and at the same time serial data access goes high to low.


STOP Condition:

void i2c_stop()
{
SCL=0;
SDA=0;
SCL=1;
SDA=1;
}


So in stop condition, serial clock goes low to and high at the same time serial data access also goes low to high and remains same until new communication not starts by master.


ACK Condition:

void i2c_ack()
{
SCL=0;
SDA=1;
SCL=1;
while(SDA==1);
}


So in acknowledge condition, serial clock goes low to high and remains high until SDA remains high until new data received


No ACK Condition:

void i2c_noack()
{
SCL=0;
SDA=1;
SCL=1;
}


So in start condition, serial clock goes low to high and at the same time serial data remains high until new data received


R/W Condition:

R/W = 0 : slave will get info that master wants to write the data at a memory location
R/W = 1 : slave will get info that master wants to read the data from a memory location


WRITE Condition:

void i2c_write_byte(unsigned char Data)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCL=0;
SDA=(Data &(0x80>>i))?1:0;
SCL=1;
}
}

here the data can be any thing

  • 7 bit slave address
  • 8 bit memory address
  • 8 bit data 
procedure will remain same same as mentioned above.



READ Condition:

unsigned char i2c_read_byte(void)
{
unsigned char i,buff=0;
for(i=0;i<8;i++)
{
SCL=0;
SCL=1;
if(SDA)
buff=buff | (0x80>>i);
}
return buff;
}


Above is a function to read data from slave at a particular address.
To read data first use write condition to enter slave address, then memory address and in last we have to use read condition.

Comments

Translate to your language

Popular posts from this blog

How to import Pygame in pycharm

hi, how are you today

Working demonstration of UART communication using 2 8051 uController on Proteus with Embedded C code.

Here we are going to use 2 at89c51 uControllers just to understand UART communication in 8051.