Discussion in "General help Guidance and Discussion" started by    shyam    Jun 30, 2013.
Sun Jun 30 2013, 08:36 pm
#1
Strictly speaking about i2c protocol



after tx of a byte ,SDA pulled low as an ACK and master further while to gain the SDA masters try to put a pulse over SCL (state num 3) this is given after SDA is pulled low by slave

but why most of master codes are written in this fashion(below) for Tx of a byte
void send_byte(unsigned char value)	//Send byte serially
{ 
	unsigned int i;
	unsigned char send;
	send=value;
	for(i=0;i<8;i++)
	{
		sda=send/128;      //Extracting MSB
		send=send<<1;    //Shiftng left
		scl=1;
		_nop_();
		_nop_();
		scl=0;
	}
   ack=sda;			        //Reading acknowledge
   sda=0;
}



observe last line why reading acknowledge is it necessary? and why to make sda=0 any wayz it will be pulled low as ACK by slave what if it is not present ?


[ Edited Sun Jun 30 2013, 08:38 pm ]
Mon Jul 01 2013, 11:46 am
#2
when reading from i2c device, master act as a kind of "pseudo slave" so according to protocol master should send ack bit to i2c device indicating data is received. If master does not make SDA=0, then a NACK is sent to i2c device and you will not receive any further data from device. Hope you get it, let me know if any further questions.
Sun Jul 07 2013, 07:16 pm
#3


when reading from i2c device, master act as a kind of "pseudo slave" so according to protocol master should send ack bit to i2c device indicating data is received. If master does not make SDA=0, then a NACK is sent to i2c device and you will not receive any further data from device. Hope you get it, let me know if any further questions.

Ajay Bhargav




i am speaking about during byte transmission observe the routine above its send byte not read
Thu Jul 11 2013, 10:24 pm
#4
@ shyam.sunder91
after each byte transmission EEPROM or any I2C device send ack
we need to check it to verify that data is received properly
in most of the cases we ignore this ack in sending data
Fri Jul 12 2013, 03:57 pm
#5
why to read acknowledgement of i2c device????????? simple... to know if ur I2C device is responding to your commands/address... but some I2C ICs like port expanders dont need Command byte. if they respond to address correctly you can simply keep sending Data Bytes without checking ACK....
Tue Jul 16 2013, 11:34 am
#6
Hope you get it this way. ACK after each byte is part of protocol. while sending byte you need not to read ack but you must send clock to shift ack bit so its not mandatory to read ack. reading ack helps to know whether your slave device is ready to accept more data or not.

You can remove following line for code from send_byte function, it will still work:
ack=sda;

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am