1
\$\begingroup\$

I am trying to interface DS1307 RTC with the MCU mentioned. I want to make a lifetime timer which tells the time this project has worked in field, and display this timer on an LCD.

I am new to microcontrollers but using LCD and I2C libraries already built-in in the MikroC pro for PIC compiler will I hope save me from low-level programming.

Now if I understand correctly, the steps to write or read something from the RTC would be:

1) I2C_Start();
2) I2C_Write(DS1307_Address);
3) I2C_Write(Register Address);
4) I2C_Write(Data to be written);
5) I2C_Stop();

and for reading:

1) I2C_Start();
2) I2C_Write(DS1307_Address);
3) I2C_Write(Register Address);
4) I2C_Repeated_Start();
5) I2C_Write(DS1307_Address);
6) I2C_Rd();
7) I2C_Stop();

My issue is that what will the DS1307_Address be, if it is the only device on the Bus?

My approach will be to set the BIT7 of 00h or CH bit of the DS1307 low whenever the device is running, and set it high just before shutting down. I do not want the RTC to count the project off time as well. Is this approach feasible?

My schematic is as following:

\$\endgroup\$
  • 1
    \$\begingroup\$ The addresses of I2C devices are usually given in their datasheet. \$\endgroup\$ – Eugene Sh. Aug 8 '16 at 14:29
  • \$\begingroup\$ Your read sequence needs another step between 3 and 4 - an "I2C Restart". \$\endgroup\$ – brhans Aug 8 '16 at 14:31
  • 2
    \$\begingroup\$ Page 12. Reading datasheets is one of the most essential skills for one dealing with electronics. With assistance of Ctrl-F it takes like 20 seconds. \$\endgroup\$ – Eugene Sh. Aug 8 '16 at 14:35
  • 1
    \$\begingroup\$ There is a I2C_Repeated_Start function. Tak a look at the examples on this page \$\endgroup\$ – Eugene Sh. Aug 8 '16 at 14:42
  • 1
    \$\begingroup\$ You can't modify a single bit. You need to read, mask, write. But I can see a small problem here. The seconds can be updated (not more than once, though, but still) during this sequence, so you will loose one second. If you don't really care about the slowly accumulated error, you can ignore it. \$\endgroup\$ – Eugene Sh. Aug 8 '16 at 14:55
1
\$\begingroup\$

As per the data sheet, page 12:

The slave address byte contains the 7-bit DS1307 address, which is 1101000, followed by the direction bit (R/W), which for a write is 0.

So the address you're looking for is 1101000.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.