Skip to main content

Read condition data frames for I2C communication

Inter-Integrated Circuit



So here we are going to learn how to receive data from slave to master. Data frame will remain same but what changes is slave address, memory address. Data from slave's memory address that we have to read.

Please go through the below frame that you have to follow while reading data from slave.

 So above image will help you to understand the  basic writing principle of  master into slave.

Steps to follow:
  • Send start bit so that each slave will get notification that some master is going to start communication.
  • Then master have transmit so that a he can communicate with a specific slave master wants to communicate among many.
  • After that acknowledge bit is transmitted to confirm that salve is understanding what master wants to convey. 
  • After selecting slave and informing slave type of operation master wants to perform, master will transmit memory address so that slave will get to know that master wants to access this specific memory location in me.
  • After that acknowledge bit is transmitted to confirm that salve is understanding what master wants to convey. 
  • Here master will send start bit again .
  • Master will then inform whether he wants to read data from that slave by sending 1 for write and read resp.[in case of read data, set the 0th bit of slave address to 1 as slave address is of 7 bit and i2c transmits MSB first, so(higher 7 bit  is slave address) LSB will be set to 1 and will inform slave that master wants to read]
  • After that acknowledge bit is transmitted to confirm that salve is understanding what master wants to convey.
  • After accessing at that specific memory location in a specific slave, master will read the data that master wants to read at that memory address.
  • After that no acknowledge bit is transmitted to confirm that salve is understanding what master wants to convey.
  • Master will send stop bit once master done with reading data from specific memory location.
  • If master have more data to read,repeat the above steps with new memory address

Programming algorithm:
Before proceeding with programming algorithm, please got through  last post so that you can get idea of each condition as I will not write whole program, I will mention algorithm(flow). 


unsigned char i2c_read_data(unsigned char sa,unsigned char addr)
{
unsigned char buff;
i2c_start();
i2c_write_byte(sa);
i2c_ack();
i2c_write_byte(addr);
i2c_ack();
i2c_start();
i2c_write_byte(sa|1);  // higher 7 bit have slave address and setting LSB(0th bit) to 1
i2c_ack();
buff=i2c_read_byte();
i2c_noack();
i2c_stop();
return buff;
}


here 
sa      : slave address
addr  : memory address


Video:


Hope you all like this post and I wish this proves useful to you.
Keep sharing & give your views about post in comments.
Comments are always welcomed for better improvement.

Thanks :)
Please write comments if you find anything needs to be more clear, incorrect, or you want to share more information about the topic discussed above 

Comments

Post a Comment

Translate to your language

Popular posts from this blog

Different Stages of I2C communication

Different Stages Of I2C

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.