I2C address specifying

Dear all,

i just copied this code from Arduino website. I wanna understand this code. How they specified i2c address has 0x68. How they taken in to consideration. Code is working fine.

how they assigned 0x68 and why they put byte Zero=0x00;

#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

main code:

#include"Wire.h"

#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

void setup(){
  Wire.begin();
  Serial.begin(9600);
  setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){
  printDate();
  delay(1000);
}

void setDateTime(){

  byte second =      45; //0-59
  byte minute =      06; //0-59
  byte hour =        11; //0-23
  byte weekDay =    2; //1-7
  byte monthDay =    27; //1-31
  byte month =       2; //1-12
  byte year  =       13; //0-99

 Wire.beginTransmission(DS1307_ADDRESS);

  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start

  Wire.endTransmission();

}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
 
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

   int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

 /*  int second = 11;
  int minute =18;
  int hour = 18;
  int weekDay = 1;
  int monthDay = 2;
  int month = 11;
  int year = 12;
*/
  //print the date EG   3/1/11 23:59:59
  Serial.print(monthDay);
  Serial.print("/");
  
  
  Serial.print(month);
  Serial.print("/");
  
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}

Each I2C device has an address, or in some cases, a range of addresses where up to three of the address bits can be set by jumpers so you can have up to eight devices of exactly the same kind on the bus, in addition to other kinds. The data sheet tells what addresses the device will respond to. The DS1307 in your code has address $68.

How this adress has being specified , For above code can u tell me how they taken 0x68 has address. Do you have any document/datasheet or links where i can get clear my doubts.

I just wanna know how they taken it has 68

Garth:
Each I2C device has an address, or in some cases, a range of addresses where up to three of the address bits can be set by jumpers so you can have up to eight devices of exactly the same kind on the bus, in addition to other kinds. The data sheet tells what addresses the device will respond to. The DS1307 in your code has address $68.

The manufacturer assigns the address for the device.

The data sheet is at http://datasheets.maximintegrated.com/en/ds/DS1307.pdf and the address is shown in the diagrams on pages 12 and 13 as the first byte sent after the start condition. The address is actually 7 bits, and the 8th bit tells it whether to read or write.

Phillips (nowadays NXP) developed the I2C protocoll for it’s own product designs in the 80s/90s. So they reserved alot of adresses for their own chips:

http://www.nxp.com/acrobat_download/sel … LGUIDE.PDF

There are only so many adresses that you can assign to chips with just 7 bits. So the adresses really identify only types of chips I suppose. Though I read for some chips the protocol can be expanded to 10 bits adresses.

hi…i have a problem…i same copy the coding into your website…but the difference is i’m using arduino board uno with ethernal shield…and the result nothing same with i only use arduino uno board